Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

May I know what exactly requireGestureRecognizerToFail will do?

Can any one let me know what exactly the below code line will do? I have referred Apples documentation but didn't get the exact picture about this,

[scrollview.panGestureRecognizer requireGestureRecognizerToFail:swipeRightGesture];
like image 687
Smith Avatar asked Feb 21 '14 07:02

Smith


2 Answers

When user make a right swipe gesture then pan gesture will be failed (ignored).

like image 158
Tomasz Szulc Avatar answered Sep 28 '22 20:09

Tomasz Szulc


An example,[_singleTap requireGestureRecognizerToFail:_doubleTap], when you want a single-tap gesture require that a double-tap gesture fail. Double-tap includes two single taps, so if no requireGestureRecognizerToFail single-tap gesture delegate method may invoke twice.

So here, swipe gesture may trigger pan gesture, then will invoke panGestureRecognizer delegate method while you are swiping actually.

If add [panGestureRecognizer requireGestureRecognizerToFail:swipeRightGesture] , once swipeRightGesture transitions to UIGestureRecognizerStateRecognized or UIGestureRecognizerStateBegan, panGestureRecognizer transitions to UIGestureRecognizerStateFailed immediately.

And only swipeRightGesture haven't transited to above RecognizerStates, there is possible for panGestureRecognizer to respond, transited to UIGestureRecognizerStateBegan, and invoke panGestureRecognizer delegate method.

like image 37
simalone Avatar answered Sep 28 '22 19:09

simalone