Swift:通过 UIView 识别滚动

Swift: Recognizing Scrolling Through UIView

我有一个 UIViewController 可以创建自定义 UIView 对象并将它们插入 UIScrollViewUIViewControllerUIPanGestureRecognizer 附加到每个 UIView。即使通过自定义 UIView 对象触摸 UIScrollView,同时仍然允许它们的 UIPanGestureRecognizers(配置为仅更改 x 坐标),我能做些什么来允许滚动 UIScrollView上班?

这是我的意思的屏幕截图。蓝色矩形是自定义 UIView 对象,白色背景是 UIScrollView

如有任何帮助,我们将不胜感激!

我想通了!

都是关于使用UIGestureRecognizerDelegate

在顶部,你做 class ViewController: UIViewController, UIGestureRecognizerDelegate

然后,在 class 正文中,添加此方法:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool { return true }

最后,在顶部的 UIView 中添加 panRecognizer.delegate = selfpanRecognizer 是引用 UIViewUIGestureRecognizer