Skip to content

Instantly share code, notes, and snippets.

@haldun
Created December 11, 2015 08:32
Show Gist options
  • Save haldun/cd920f91fea26e930824 to your computer and use it in GitHub Desktop.
Save haldun/cd920f91fea26e930824 to your computer and use it in GitHub Desktop.
protocol TimedTapGestureRecognizerDelegate: class {
func delayInSecondsForTimedTapGestureRecognizer(recognizer: TimedTapGestureRecognizer) -> Double
}
final class TimedTapGestureRecognizer: UITapGestureRecognizer {
weak var timedTapGestureRecognizerDelegate: TimedTapGestureRecognizerDelegate?
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent) {
super.touchesBegan(touches, withEvent: event)
let delayDuration = timedTapGestureRecognizerDelegate?.delayInSecondsForTimedTapGestureRecognizer(self) ?? 0.4
delay(delayDuration) {
if self.state != .Recognized {
self.state = .Failed
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment