Reputation: 513
I've been fighting with UIScrollView for a while now. I have a scroll view which has multiple 'card' style views in it. I want the cards to move vertically, as in swiping up and down.
Imagine MobileSafari's tab view, but with swipe down to close tabs.
I can't figure out how to do this without it conflicting with the scroll view horizontal panning. I either get them both panning, or only one panning (vertical / horizontal).
What's the best practice to make this work perfectly, as in "if you're swiping vertically, stop horizontal swiping, and if you're swiping horizontally, stop vertical swiping".
Thank you!
Here's an illustration of what I want :
Upvotes: 2
Views: 2523
Reputation: 53119
I'm really confused by the intended behaviour of your app here. You are using swipe and panning interchangeably but they are different gesture recognizers.
Well one way to differentiate is to compare the x and y values of the translationInView:
method of the gesture. If y > x, you have a vertical swipe/pan; x > y and you have a horizontal swipe/pan.
Make that gesture recognizer fail if the swipe/pan detected is not the type you are looking out for.
Upvotes: 2
Reputation: 126107
The scroll view has its own gesture recognizer: see its panGestureRecognizer
property. If you add your own recognizer for detecting the vertical swipe, you can use requireGestureRecognizerToFail:
or delegate methods to manage dependencies between the two recognizers.
Upvotes: 6