UILongPressGestureRecognizer missing UIGestureRecognizerStateBegan state!
so I have implemented a 1-finger long-press gesture recognizer, but the recognizer always seems to be missing the UIGestureRecognizerStateBegan state... If I long press w/o moving finger and lift, I get the StateEnded debug message. If I long press and move finger a bit then lift, I get the StateChanged and StateEnded debug messages. But I never see StateBegan.
Don't have this issue with UIPanGestureRecognizer - Pan gets all the correct gesture states from Began->Changed->Ended.
- (void)handleLongPress:(UILongPressGestureRecognizer *)recognizer {
CGPoint location = [recognizer locationInView:self];
switch (recognizer.state) {
case UIGestureRecognizerStateBegan:
NSLog(@"!!!!handleLongPress: StateBegan !!!开发者_如何学Go!!");
break;
case UIGestureRecognizerStateChanged:
NSLog(@"!!!!handleLongPress: StateChanged !!!!!");
break;
case UIGestureRecognizerStateEnded:
NSLog(@"!!!!handleLongPress: StateEnded !!!!!");
break;
default:
break;
}
}
I was having a similar problem and it was caused by the UILongPressGestureRecognizer setup: the original sample code I was using specified the numberOfTapsRequired = 1, and I had to quick-tap and release, and THEN long-tap to make it work, instead of just tapping and holding for a couple of seconds. When I removed the numberOfTapsRequired the code now behaved as I expected. Hope this helps =)
精彩评论