Skip to content

Instantly share code, notes, and snippets.

@jbrennan
Created December 29, 2015 22:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jbrennan/5bb0fe34988594dd7be0 to your computer and use it in GitHub Desktop.
Save jbrennan/5bb0fe34988594dd7be0 to your computer and use it in GitHub Desktop.
A UIPanGestureRecognizer subclass to recognize immediately. Is this a good idea?
@implementation ImmediatePanGestureRecognizer
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
if (self.numberOfTouches >= self.minimumNumberOfTouches) {
self.state = UIGestureRecognizerStateBegan;
}
}
- (void)setState:(UIGestureRecognizerState)state {
// We don't want to enter the begin state if we've already began.
// Need to do this because we're prematurely firing "Began" on touches began
// and UIPGR will fire it somewhere else (presumably -touchesMoved:)
if (self.state == UIGestureRecognizerStateBegan && state == UIGestureRecognizerStateBegan) {
return;
}
[super setState:state];
}
@end
@jbrennan
Copy link
Author

Blech, although this gets rid of the need for touch movement before it starts, there still seems to be about a 1 second (!!!) delay between when I tell the gesture recognizer to start and when I get my action callback.

Instead, I’m just reverting back to using UILongPressGestureRecognizer with a short duration and a large allowable movement. Works better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment