UIGestureRecognizer Swift subclass enabling 3D Touch
CocoaPods is a dependency manager for Cocoa projects. To install ForceTouchGestureRecognizer.swift with CocoaPods:
-
Make sure CocoaPods is installed.
-
Update your Podfile to include the following:
pod 'ForceTouchGestureRecognizerSwift', git: 'https://github.com/ashleymills/ForceTouchGestureRecognizer.swift'
-
Run
pod install
.
Just drop the ForceTouchGestureRecognizer.swift file into your project. That's it!
override func viewDidLoad() {
super.viewDidLoad()
let forceTouchGesture = ForceTouchGestureRecognizer(target: self, action: "pressView:")
forceTouchGesture.minimumValue = 0.1 // Minimum force value before touch is recognised
forceTouchGesture.tolerance = 0.2 // Allows the pressure to be lifted slightly without the gesture ending
view.addGestureRecognizer(forceTouchGesture)
}
func pressView(gesture: ForceTouchGestureRecognizer) {
print("force: \(gesture.forceValue)") // forceVouch is CGFloat between 0 & 1
}
Got a bug fix, or a new feature? Create a pull request and go for it!
Cheers, Ash