I am developing an application where I have used the Pan Gesture as well as Swipe Gesture. So every time I do the Swipe Gesture but the method from the Pan Gesture is always getting called and Swipe Gesture method is not getting called.
Is there any priority between all the gesture method?
You can call them in parallel by implementing the following method of the
UIGestureRecognizerDelegate
protocol:There is a property on the
UIGestureRecognizer
class called "cancelsTouchesInView" which defaults toYES
. This will cause any pending gestures to be canceled. The Pan gesture is getting recognized first since it does not need to have a "touch up" event, so it cancels the Swipe gesture.If you want both gestures to be recognized, try adding:
[yourPanGestureInstance setCancelsTouchesInView:NO];
Give priority to swipe
You can give priority to a
UIGestureRecognizer
with therequire(toFail:)
method.Now your pan will only execute if your swipe fails.
Use pan for everything
If the swipe and pan gesture recognizers don't play nicely with this setup, you can roll all of your logic into the pan gesture recognizer for more control.
Here's a demo of the above code in action.