Created
November 11, 2016 23:11
-
-
Save mbehan/25e315f05686b87b28a376c6434f9c5e to your computer and use it in GitHub Desktop.
A UIPanGestureRecognizer subclass to get the force of the gesture's touch (assumes a single touch)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import UIKit.UIGestureRecognizerSubclass | |
class ForcePanGestureRecognizer : UIPanGestureRecognizer { | |
private(set) var force = CGFloat(0) { | |
didSet { | |
if force > maxForce { | |
maxForce = force | |
} | |
} | |
} | |
private(set) var maxForce = CGFloat(0) | |
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent) { | |
maxForce = CGFloat(0) | |
force = touches.first!.force | |
super.touchesBegan(touches, with: event) | |
} | |
override func touchesMoved(_ touches: Set<UITouch>, with event: UIEvent) { | |
force = touches.first!.force | |
super.touchesMoved(touches, with: event) | |
} | |
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent) { | |
force = touches.first!.force | |
super.touchesEnded(touches, with: event) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment