0
votes

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 !!!!!");
            break;
        case UIGestureRecognizerStateChanged:
            NSLog(@"!!!!handleLongPress: StateChanged !!!!!");
            break;
        case UIGestureRecognizerStateEnded:
            NSLog(@"!!!!handleLongPress: StateEnded !!!!!");
            break;
        default:
            break;
    }   
}
1
Your code seems to be working fine for me. Have you setup any sort of dependencies between your tap and pan gesture recognizers or do you also have any other recognizers on that view?Jason Foreman
no dependencies between any of my gesture recognizers. and yes, i do have several recognizers on this view. i'm stumped... :(annie

1 Answers

1
votes

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 =)