I have a gesture recognizer on a UIScrollView, however it hardly ever gets called as the UIScrollView eats all the gestures.
I partially got around this issue with this line: [scrollView.panGestureRecognizer requireGestureRecognizerToFail:rightSwipe];
however, this line results in my recognizer always being accepted (the desired behavior) and the scroll view not scrolling.
That is, when you scroll, the recognizer is accepted but the view doesn't scroll.
How can I get around this, or is there an alternate solution?
Thanks!
The way that works for me is subclass
UIScrollView
and conform toUIGestureRecognizerDelegate
in that subclass. Then call the method.Don't forget to assign proper delegation to your gesture recognizer mechanism:
So, for example:
Set a
.up
direction gesture recognizerSet a
.down
direction gesture recognizerAlso don't forget to conform to delegation:
Set simultaneous recognition:
Then move on to your logic...
Hope it helps!
Make a subclass of
UIScrollView
. Add this method in your new subclassMake your scrollView class to your new scrollview subclass.
Swift method,
Need to add UIGestureRecognizerDelegate to your class:
Need to set its delegate to self:
Add this part in your class methods to active simultaneous gestures: