Easy Haptic Feedback Generator 📳

Overview

Haptica

Build Status Carthage Compatible Language Version License Platform

Haptica is an easy haptic feedback generator.

$ pod try Haptica

Requirements

  • iOS 9.0+
  • Xcode 8.0+
  • Swift 5 (Haptica 3.x), Swift 4 (Haptica 2.x), Swift 3 (Haptica 1.x)

Haptic Feedback Requirements:

  • A device with a supported Taptic Engine.
  • App is running in the foreground.
  • System Haptics setting is enabled.

Usage

Generate using a haptic feedback type.

Haptic.impact(.light).generate()

Feedback Types

  • Impact: (UIImpactFeedbackStyle) - Use impact feedback generators to indicate that an impact has occurred. For example, you might trigger impact feedback when a user interface object collides with something or snaps into place.
    • light
    • medium
    • heavy
  • Notification: (UINotificationFeedbackType) - Use notification feedback to communicate that a task or action has succeeded, failed, or produced a warning of some kind.
    • success
    • warning
    • error
  • Selection - Use selection feedback to communicate movement through a series of discrete values.

Vibration Patterns

Play a custom vibration pattern:

Haptic.play("..oO-Oo..", delay: 0.1)

Use pattern symbols to represent custom vibrations.

  • O - heavy impact
  • o - medium impact
  • . - light impact
  • X - rigid impact
  • x - soft impact
  • - - wait 0.1 second

Or play a symphony of notes:

Haptic.play([.haptic(.impact(.light)), .haptic(.impact(.heavy)), .wait(0.1), .haptic(.impact(.heavy)), .haptic(.impact(.light))])

UIButton Extension

To enable haptic feedback on buttons, set these properties:

  • isHaptic - enables haptic feedback
  • hapticType - haptic feedback type
button.isHaptic = true
button.hapticType = .impact(.light)

or use these functions to set the haptic feedback type for control events:

  • addHaptic() - add haptic feedback for control events
  • removeHaptic() - remove haptic feedback for control events
button.addHaptic(.selection, forControlEvents: .touchDown)
button.removeHaptic(forControlEvents: .touchDown)

Functions/Properties

var isHaptic: Bool // enables haptic feedback
var hapticType: Haptic? // haptic feedback type
var hapticControlEvents: UIControl.Event? // haptic feedback control events
func addHaptic(_ haptic: Haptic, forControlEvents events: UIControl.Event) {} // add haptic feedback for control events
func removeHaptic(forControlEvents events: UIControl.Event) {} // remove haptic feedback for control events

Sound Effects

Add sound effects to Haptica using Peep.

Peep.play(sound: KeyPress.tap)

Installation

CocoaPods

To install with CocoaPods, simply add this in your Podfile:

use_frameworks!
pod "Haptica"

Carthage

To install with Carthage, simply add this in your Cartfile:

github "efremidze/Haptica"

Communication

  • If you found a bug, open an issue.
  • If you have a feature request, open an issue.
  • If you want to contribute, submit a pull request.

Mentions

License

Haptica is available under the MIT license. See the LICENSE file for more info.

Comments
  • Public API improvements

    Public API improvements

    There is no real issue and this topic is more of an observation type.

    Q.1: I used Haptica as:

    button.isHaptic = true // required call.
    button.hapticType = .impact(.light) // optional, but has to be set.
    button.hapticControlEvents = .touchUpInside // optional, default is .touchDown as per implementation.
    

    My initialization logic has a flaw since button.isHaptic = true immediately triggers a call to addTarget() with .touchDown as default value (if hapticControlEvents is not set). Hence hapticControlEvents should be initialized before button.isHaptic = true invocation to make any effect.

    Would this make sense to refactor and introduce methods like these:

    func addHaptic(_ haptic: Haptic, forControlEvents events: UIControl.Event = .touchUpInside)
    func removeHaptic()
    

    to enable 1 line setup? Methods naming strategy 'addHaptic', 'removeHaptic' stolen from 'addTarget', 'removeTarget'.

    Q.2: Does it make sense to implement Hapticable for UIControl rather than UIButton? (since addTarget and removeTargets methods implemented in UIControl). This would enable Haptics for elements like UISwitch.

    opened by genkernel 3
  • Updated support for SPM

    Updated support for SPM

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by rcasula 2
  • Updated to Swift 4.2 Xcode 10

    Updated to Swift 4.2 Xcode 10

    Checklist

    • [ ] I've tested my changes.
    • [ ] I've read the Contribution Guidelines.
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by IgorMuzyka 2
  • Rigid and Soft - would you consider adding them to the vibration pattern symbols? Thanks!

    Rigid and Soft - would you consider adding them to the vibration pattern symbols? Thanks!

    opened by chrisperfer 1
  • iOS 13 feedback types support

    iOS 13 feedback types support

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Motivation and Context

    Two new types of feedback intensity in iOS13 which are not handled or mapped in Haptica.

    Description

    Added soft and rigid types of feedback and updated the example app.

    opened by kirillivonin 1
  • Fixed SwiftPM manifest

    Fixed SwiftPM manifest

    Checklist

    • [ ] I've tested my changes.
    • [ ] I've read the Contribution Guidelines.
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    Description

    opened by rafaelfrancisco-dev 1
  • Random crashes, exception UIFeedbackHapticOnlyEngine _deactivate

    Random crashes, exception UIFeedbackHapticOnlyEngine _deactivate

    I am using Haptica in my app I recently release a new version of my app on 16 July after that repeating crashes are reported on Xcode organiser. Below are the exception details:-

    ERROR: -[_UIFeedbackHapticOnlyEngine _deactivate] called more times than the feedback engine was activated

    Fatal Exception: NSInternalInconsistencyException 0 CoreFoundation 0x1f7bc927c __exceptionPreprocess 1 libobjc.A.dylib 0x1f6da39f8 objc_exception_throw 2 CoreFoundation 0x1f7ae2988 +[_CFXNotificationTokenRegistration keyCallbacks] 3 Foundation 0x1f85a6188 -[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] 4 UIKitCore 0x224055628 -[_UIFeedbackEngine _deactivate] 5 UIKitCore 0x22403e58c -[UIFeedbackGenerator __deactivateWithStyle:] 6 libdispatch.dylib 0x1f7608a38 _dispatch_call_block_and_release 7 libdispatch.dylib 0x1f76097d4 _dispatch_client_callout 8 libdispatch.dylib 0x1f75b7004 _dispatch_main_queue_callback_4CF$VARIANT$mp 9 CoreFoundation 0x1f7b5ac1c CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE 10 CoreFoundation 0x1f7b55b54 __CFRunLoopRun 11 CoreFoundation 0x1f7b550b0 CFRunLoopRunSpecific 12 GraphicsServices 0x1f9d5579c GSEventRunModal 13 UIKitCore 0x2244cf978 UIApplicationMain 14 Qpay 0x102253268 main + 16 (GeneratePasscodeInteractor.swift:16) 15 libdyld.dylib 0x1f761a8e0 start

    Haptica version:- 3.0.0 Thanks

    opened by raviatri 1
  • Update Hapticable.swift

    Update Hapticable.swift

    'cannot assign to property' fix

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [ ] I've updated the documentation if necessary.

    Motivation and Context

    this change will solve cannot assign to property: 'self' is immutable error for cases when trying to assign property inside subclass c-tor

    Sample code:

    class MyButtonSubclass: UIButton {
        override init(frame: CGRect) {
            super.init(frame: frame)
            isHaptic = true
            hapticType = .impact(.heavy)
        }
    }
    
    opened by Kirow 1
  • Swift 5.0

    Swift 5.0

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Description

    • Added Swift 5.0 Support
    opened by efremidze 0
  • 2.2.2

    2.2.2

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Description

    Lowers the Deployment Target to 9.0 whereas for devices lower than iOS 10 it simply does nothing.

    opened by efremidze 0
  • Lower Deployment Target to 9.0

    Lower Deployment Target to 9.0

    Checklist

    • [x] I've tested my changes.
    • [x] I've read the Contribution Guidelines.
    • [x] I've updated the documentation if necessary.

    Motivation and Context

    Library is hard/impossible to use via carthage if the host project has a Deployment Target of 9.0. I do know that inside the CONTRIBUTING.md it is stated to not lower the deployment target. But still, I would prefer to at least have the option to use the framework and add extra functionality with ease for my users that are >=iOS 10.0 without any hassle.

    Description

    Lowers the Deployment Target to 9.0 whereas for devices lower than iOS 10 it simply does nothing.

    opened by EternalBlack 0
  • How to stop while playing a note

    How to stop while playing a note

    How to stop while playing a long pattern

    Haptic.play("OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO", delay: 0.1)

    I want to stop this when this is playing. Please show me a way to do it.

    thanks

    opened by amith-ranasinghe 1
  • How do you do a double tap?

    How do you do a double tap?

    I tried with the following pattern but nothing simulates a double tap, how do I do that?

    addButton(pattern: "O") addButton(pattern: "o") addButton(pattern: ".") addButton(pattern: ".-.") addButton(pattern: "o-o") addButton(pattern: "O-O") addButton(pattern: "..oO-Oo..") addButton(pattern: "O--O") addButton(pattern: "o--o") addButton(pattern: "o---o") addButton(pattern: "O---O") addButton(pattern: "o--O--O--o") addButton(pattern: "o--O---O--o") addButton(pattern: "O--O---O--O") addButton(pattern: "OOO------------------------OOO")

    opened by dpyy 0
  • Usage in table view?

    Usage in table view?

    Thanks for this great library!

    I'm trying to use it in a table view, and I have the following code:

    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
      Haptic.impact(.medium).generate()
      // Other stuff...
    }
    

    This generates haptic feedback, but sometimes it seems to be generating two very fast consecutive ones. It happens when you click on one cell and then another.

    Is it the wrong way to use the library? Thank you!

    opened by danqing 0
Releases(3.0.3)
Owner
Lasha Efremidze
#iOS Engineer @amzn @EdisonJunior (Ring). Previously @eBay @stubhub @calaborate (Klutch). Open source enthusiast.
Lasha Efremidze
An easy to use FAQ view for iOS written in Swift

FAQView An easy to use FAQ view for iOS written in Swift. This view is a subclass of UIView. Setup with CocoaPods If you are using CocoaPods add this

Mukesh Thawani 467 Dec 5, 2022
Kit for building custom gauges + easy reproducible Apple's style ring gauges.

GaugeKit ##Kit for building custom gauges + easy reproducible Apple's style ring gauges. -> Example Usage Open GaugeKit.xcworkspace and change the sch

Petr Korolev 1k Dec 23, 2022
An easy way to add a shimmering effect to any view with just one line of code. It is useful as an unobtrusive loading indicator.

LoadingShimmer An easy way to add a shimmering effect to any view with just single line of code. It is useful as an unobtrusive loading indicator. Thi

Jogendra 1.4k Jan 4, 2023
Powerful and easy-to-use vector graphics Swift library with SVG support

Macaw Powerful and easy-to-use vector graphics Swift library with SVG support We are a development agency building phenomenal apps. What is Macaw? Mac

Exyte 5.9k Jan 1, 2023
An iOS Library that makes shadows management easy on UIView.

ShadowView is an iOS Shadow library that makes view's shadow implementation easy and sweet ?? ?? . Add simple shadows to add a gaussian blurred projec

Pierre 404 Dec 8, 2022
Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle.

Twinkle ✨ Twinkle is a Swift and easy way to make any UIView in your iOS or tvOS app twinkle. This library creates several CAEmitterLayers and animate

patrick piemonte 600 Nov 24, 2022
An easy to use UI component to help display a signal bar with an added customizable fill animation

TZSignalStrengthView for iOS Introduction TZSignalStrengthView is an easy to use UI component to help display a signal bar with an added customizable

TrianglZ LLC 22 May 14, 2022
UIPheonix is a super easy, flexible, dynamic and highly scalable UI framework + concept for building reusable component/control-driven apps for macOS, iOS and tvOS

UIPheonix is a super easy, flexible, dynamic and highly scalable UI framework + concept for building reusable component/control-driven apps for macOS, iOS and tvOS

Mohsan Khan 29 Sep 9, 2022
Windless makes it easy to implement invisible layout loading view.

Windless Windless makes it easy to implement invisible layout loading view. Contents Requirements Installation Usage Looks Credits Communication Licen

ArLupin 940 Dec 22, 2022
Easy-to-use HStack that snaps to elements on scroll.

SnapToScroll Drop-in SwiftUI-based container view for horizontal snapping. example-video.mp4 Getting Started Using SnapToScroll is straightforward. Th

null 206 Jan 7, 2023
An easy to use FAQ view for iOS written in Swift

FAQView An easy to use FAQ view for iOS written in Swift. This view is a subclass of UIView. Setup with CocoaPods If you are using CocoaPods add this

Mukesh Thawani 466 Nov 9, 2021
A UIControl subclass that makes it easy to create empty states.

AZEmptyState Making empty state simple. Screenshots Installation Cocoa Pods: pod 'AZEmptyState' Manual: Simply drag and drop the Sources folder to you

Antonio Zaitoun 88 Oct 2, 2022
Easy to use, highly customizable gauge view

GDGauge - Customizable Gauge View Requirements Xcode 11+ Swift 5 iOS 9+ Installation Swift Package Manager .package(url: "https://github.com/saeid/GDG

Saeid 74 Dec 5, 2022
🧩 Easy scrollable layouts in UIKit

Easy scrollable layouts in UIKit Create complex scrollable layout using UIViewControllers or plain UIViews and simplify your code! ScrollStackControll

Daniele Margutti 402 Oct 3, 2022
CITreeView created to implement and maintain that wanted TreeView structures for IOS platforms easy way

CITreeView CITreeView created to implement and maintain that wanted TreeView structures for IOS platforms easy way. CITreeView provides endless treevi

Cenk Işık 126 May 28, 2022
Haptico 📳 - easy to use haptic feedback generator with pattern-play support

Haptico Haptico is easy to use iOS haptic feedback generator. Besides default haptic feedbacks it can play patterns! Checkout Example project. Table o

Sapozhnik Ivan 462 Jan 1, 2023
Easy Haptic Feedback Generator 📳

Haptica is an easy haptic feedback generator. $ pod try Haptica Requirements iOS 9.0+ Xcode 8.0+ Swift 5 (Haptica 3.x), Swift 4 (Haptica 2.x), Swift

Lasha Efremidze 702 Jan 1, 2023
TapticEngine generates haptic feedback vibrations on iOS device.

TapticEngine Overview TapticEngine generates haptic feedback vibrations on iOS device. This library wrapps on UIImpactFeedbackGenerator, UISelectionFe

WorldDownTown 253 Oct 28, 2022
✨ Super easy Parallax and Haptic Effect.

IParallaxAndHapticEffect ✨ Super easy Parallax and Haptic Effect. This library helps you easily use the 'Parallax' and 'Haptic' effects. Customized 3D

Hae Chan 2 Feb 9, 2022
Spin aims to provide a versatile Feedback Loop implementation working with the three main reactive frameworks available in the Swift community (RxSwift, ReactiveSwift and Combine)

With the introduction of Combine and SwiftUI, we will face some transition periods in our code base. Our applications will use both Combine and a thir

Spinners 119 Dec 29, 2022