Skip to content

ashleymills/ForceTouchGestureRecognizer.swift

Repository files navigation

ForceTouchGestureRecognizer.swift

UIGestureRecognizer Swift subclass enabling 3D Touch

Installation

CocoaPods

CocoaPods is a dependency manager for Cocoa projects. To install ForceTouchGestureRecognizer.swift with CocoaPods:

  1. Make sure CocoaPods is installed.

  2. Update your Podfile to include the following:

    pod 'ForceTouchGestureRecognizerSwift', git: 'https://github.com/ashleymills/ForceTouchGestureRecognizer.swift'
  3. Run pod install.

Manual

Just drop the ForceTouchGestureRecognizer.swift file into your project. That's it!

Example use

    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
    }

Want to help?

Got a bug fix, or a new feature? Create a pull request and go for it!

Cheers, Ash

About

UIGestureRecognizer Swift subclass enabling 3D Touch

Resources

License

Stars

Watchers

Forks

Packages

No packages published