[英]UIPanGestureRecognizer with UIScrollView
I've been fighting with UIScrollView for a while now. 我已经和UIScrollView争了一段时间了。 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. 想象一下MobileSafari的标签视图,但向下滑动以关闭标签。
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 : 这是我想要的例子:
The scroll view has its own gesture recognizer: see its panGestureRecognizer
property. 滚动视图有自己的手势识别器:请参阅其panGestureRecognizer
属性。 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. 如果添加自己的识别器以检测垂直滑动,则可以使用requireGestureRecognizerToFail:
或委托方法来管理两个识别器之间的依赖关系。
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. 那么区分的一种方法是比较手势的translationInView:
方法的x和y值。 If y > x, you have a vertical swipe/pan; 如果y> x,则表示垂直滑动/平移; x > y and you have a horizontal swipe/pan. x> y,你有一个水平滑动/平移。
Make that gesture recognizer fail if the swipe/pan detected is not the type you are looking out for. 如果检测到的滑动/平移不是您要查找的类型,请使手势识别器失败。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.