Created
December 29, 2015 22:42
-
-
Save jbrennan/5bb0fe34988594dd7be0 to your computer and use it in GitHub Desktop.
A UIPanGestureRecognizer subclass to recognize immediately. Is this a good idea?
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
@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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.