How would you setup the gesture recognizers so that you could have a UISwipeGestureRecognizer and a UIPanGestureRecognizer work at the same time? Such that if you touch and move quickly (quick swipe) it detects the gesture as a swipe but if you touch then move (short delay between touch & move) it detects it as a pan?
I've tried various permutations of requireGestureRecognizerToFail and that didn't help exactly, it made it so that if the SwipeGesture was left then my pan gesture would work up, down and right but any movement left was detected by the swipe gesture.
Here is a full solution for detecting pan and swipe directions (utilizing 2cupsOfTech's swipeThreshold logic):
Usage:
By default, when the user attempts to swipe, the gesture is interpreted as a pan. This is because a swiping gesture meets the necessary conditions to be interpreted as a pan (a continuous gesture) before it meets the necessary conditions to be interpreted as a swipe (a discrete gesture).
You need to indicate a relationship between two gesture recognizers by calling the requireGestureRecognizerToFail: method on the gesture recognizer that you want to delay
You're going to want to set one of the two
UIGestureRecognizer
's delegates to an object that makes sense (likelyself
) then listen, and returnYES
for this method:This method is called when recognition of a gesture by either
gestureRecognizer
orotherGestureRecognizer
would block the other gesture recognizer from recognizing its gesture. Note that returningYES
is guaranteed to allow simultaneous recognition; returningNO
, on the other hand, is not guaranteed to prevent simultaneous recognition because the other gesture recognizer's delegate may returnYES
.Using a pan recognizer to detect swipping and panning: