IOS Combining longPress and swipe gestures

  • I am adding swipeUp gesture to the whole view.

  • I add a longPressGestureRecognizer to the whole view, set its minimunPressDuration to 0.001f so that it can both detect when the action is clicked and touch the move action, and then call the requireGestureToFail function:

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

      

The problem is this:

When the user presses and holds (does not move) the button, the longPress gesture state remains UIGestureStatePossible because the swipeUp gesture is not interrupted, so it will not respond to touch presses.

If I do not call requireGestureRecognizerToFail, all gestures, including swipeUp gestures, will be recognized as longPress gesture.

Implmenting shouldRecognizeSimultaneousWithGestureRecognizer: not what i expect.

What I want is to press and hold the button (do not move) on the button, it triggers longPress and then if the user scrolls up it triggers a swipeUp gesture, if the user is dragging but the touch pattern is not suitable for swipeUp it does runs longPress equally.

How to implement this?

+3


source to share


1 answer


I think it would be easier to implement a custom UIGestureRecognizer or a UIView subclass with a few gestures. Check this out:

UITapGestureRecognizer - make it work on touch instead of touch?

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



0


source







All Articles