4
votes

I'm using two gesture recognizers on my UIView. One is standard UITapGestureRecognizer, another is very simple touch down recognizer I wrote:

@implementation TouchDownGestureRecognizer

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    if (self.state == UIGestureRecognizerStatePossible) {
        self.state = UIGestureRecognizerStateRecognized;
    }
}

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    self.state = UIGestureRecognizerStateFailed;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
    self.state = UIGestureRecognizerStateFailed;
}

@end

They work together only if I assign a delegate to both of them that contains this method:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {
    return YES;
}

It's all working fine, but when I perform a long press on that view, touch down recognizer fires and touch up recognizer doesn't. For short taps everything is fine, they both fire.

I implemented all methods in UIGestureRecognizerDelegate to return YES to no avail. If I'm adding logging to see the interaction with delegate and inside my own recognizer, I can see that for both short and long taps the invocations sequence is identical — except for the call to touch up recognizer. What do I do wrong?

1

1 Answers

6
votes

Why don't you just check the touchUp directly from the UILongPressGestureRecognizer?

-(void)selectionDetected:(UILongPressGestureRecognizer*)longPress
{
    if(longPress.state==1)
    {
       //long Press is being held down
    }
    else if(longPress.state==3)
    {
        //the touch has been picked up
    }
}