简体   繁体   English

使用UIScrollView的UIPanGestureRecognizer

[英]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.

相关问题 UIPanGestureRecognizer requireGestureRecognizerToFail延迟UIScrollView - UIPanGestureRecognizer requireGestureRecognizerToFail delays UIScrollView 使用UIScrollView进行查看时的UIPanGestureRecognizer - UIPanGestureRecognizer at view with UIScrollView iOS Swift:UIScrollView中的UIPanGestureRecognizer - iOS Swift: UIPanGestureRecognizer in UIScrollView 如何将UIPanGestureRecognizer添加到UIScrollView子视图 - How to add UIPanGestureRecognizer to UIScrollView subviews 屏幕顶部边缘的 UIScrollView UIPangestureRecognizer 死区 - UIScrollView UIPangestureRecognizer dead zone on top edge of screen 将我自己的UIPanGestureRecognizer与UIScrollView的配对 - Pairing my own UIPanGestureRecognizer with that of UIScrollView's 当我向 UIScrollView 添加一个 UIPangesturerecognizer 时,滚动被禁用 - Scrolling is disabled when i add A UIPangesturerecognizer to UIScrollView 阻止UIScrollView的UIPanGestureRecognizer阻止UIScreenEdgePanGestureRecognizer - Prevent UIScrollView's UIPanGestureRecognizer from blocking UIScreenEdgePanGestureRecognizer UIPanGestureRecognizer用于UIScrollView内的UIImageView内的UIImageView - UIPanGestureRecognizer for UIImageView inside UIImageView inside UIScrollView 在UIScrollView内时,阻止UIPanGestureRecognizer垂直移动UIView - Stop UIPanGestureRecognizer from moving UIView vertically when inside a UIScrollView
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM