3
  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?

AveryLiu
  • 819
  • 8
  • 18

1 Answers1

0

I think it would be easier to implement your own UIGestureRecognizer or UIView subclass with multiple gestures. Check this out:

UITapGestureRecognizer - make it work on touch down, not touch up?

https://developer.apple.com/library/ios/documentation/EventHandling/Conceptual/EventHandlingiPhoneOS/GestureRecognizer_basics/GestureRecognizer_basics.html#//apple_ref/doc/uid/TP40009541-CH2-SW2

Community
  • 1
  • 1
ArturOlszak
  • 2,653
  • 2
  • 21
  • 20