Question

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];
Was it helpful?

Solution

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

OTHER TIPS

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.

The accepted answer is only partially correct...

According to the docs for requireGestureRecognizerToFail:

The state that the receiver transitions to depends on what happens with otherGestureRecognizer [the second referenced gesture recognizer]:

  • If otherGestureRecognizer transitions to UIGestureRecognizerStateFailed, the receiver transitions to its normal next state.

  • If otherGestureRecognizer transitions to UIGestureRecognizerStateRecognized or UIGestureRecognizerStateBegan, the receiver transitions to UIGestureRecognizerStateFailed.

This means that in the following code:

[scrollview.panGestureRecognizer requireGestureRecognizerToFail:swipeRightGesture];

When the user makes a swipe gesture, the pan gesture will only fail if that swipe gesture proceeds as normal. If that swipe gesture fails however, the pan gesture will proceed instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top