Swift:通过 UIView 识别滚动
Swift: Recognizing Scrolling Through UIView
我有一个 UIViewController
可以创建自定义 UIView
对象并将它们插入 UIScrollView
。 UIViewController
将 UIPanGestureRecognizer
附加到每个 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 = self
(panRecognizer
是引用 UIView
的 UIGestureRecognizer
我有一个 UIViewController
可以创建自定义 UIView
对象并将它们插入 UIScrollView
。 UIViewController
将 UIPanGestureRecognizer
附加到每个 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 = self
(panRecognizer
是引用 UIView
的 UIGestureRecognizer