HapticButton
A button that is triggered based on the 3D Touch pressure, similar to the iOS 11 control center.
HapticButton
replicates the behavior of the buttons in the iOS 10 and 11 Control Center as well as in the Home app. A device with 3D Touch is required to fully experience the haptic feedback on supported devices. It is implemented as a subclass of UIControl
, so feel free to further customize it to your needs.
The user is required to press the button and activate 3D Touch with a minimum pressure threshold (you can specify the minimum value to trigger the button via the feedbackThreshold
property). This allows for a cool interaction that gives a haptic feedback to the user when the button is triggered. ?
For the best experience, install the example on a device. ?
The example project shows how to set up HapticButton
in a few different ways.
- Create a button with a
UILabel
. Use theHapticButtonDelegate
to be notified when the button is triggered.
- Create a button with a
UIImageView
and a blur background. Use the standardUIControl
event to subscribe to the touch up inside event.
- Create a button with a customized
UILabel
and dark blur background. Subcribe to the button events through a closure.
? Customizations
These are the public properties that allow you to customize the control. In case you are thinking to modify HapticButton
even further, consider creating a Pull Request! ??
? Requirements
iOS 10.0 and Swift 3.2 are required.
If you are using Swift 4, please use the swift4 branch.
Installation
HapticButton
is available through CocoaPods. To install
it, simply add the following line to your Podfile
:
You can also use Carthage if you prefer. Add this line to your Cartfile
.