Created
February 16, 2017 04:47
-
-
Save SAllen0400/18b7799f8195fbf91a11a844d368cbc9 to your computer and use it in GitHub Desktop.
Get length of Long Press Gesture
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
// Swift 3 | |
// If you'd like to use the gestureDuration outside of the scope of the button press, create some variables. | |
var gestureStartTime: TimeInterval! | |
var gestureDuration: TimeInterval! | |
// IBAction for UILongPressGestureRecognizer | |
@IBAction func recordButtonHeld(_ sender: UILongPressGestureRecognizer) { | |
switch sender.state { | |
case .began: | |
// By default, .began triggers after the button is held for 0.5 seconds. | |
// This can be adjusted by changing the minimumPressDuration property | |
gestureStartTime = Date.timeIntervalSinceReferenceDate | |
case .ended: | |
gestureDuration = Date.timeIntervalSinceReferenceDate - gestureStartTime | |
default: | |
break | |
} | |
} | |
// Now you have the gestureDuration value in a variable and can use it however you like in your code. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment