3
votes
  1. I add a swipeUp gesture to the whole view.

  2. I add a longPressGestureRecognizer to the whole view, set its minimunPressDuration equals 0.001f so that it can both detect press down action and touches move action, then call the requireGestureToFail function:

 UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressed:)];
 longPressGestureRecognizer.minimumPressDuration = 0.001f; 
 [longPressGestureRecognizer requireGestureRecognizerToFail:swipeGestureRecognizer];

The problem is:

When user press and hold (don't move) a button, the longPress gesture's state remains UIGestureStatePossible because the swipeUp gesture doesn't fail, So that it won't react to user touch.

If I don't call requireGestureRecognizerToFail all the gesture including swipeUp gesture will be recognised as longPress gesture.

Implmenting shouldRecognizeSimultaneouslyWithGestureRecognizer: is not what I expect.

What I want is when press and hold(don't move) a button, it triggers longPress, then if user swipe up it triggers swipeUp gesture, if user drags but the touch pattern doesn't fit swipeUp it still triggers longPress.

How can I implement this?

1
Have you tried reversing it? Maybe the swipe should require the long press to fail.TylerP
Thanks, but it doesn't work. Still, all the gesture is recognised as longPress.AveryLiu

1 Answers