Swift:通过UIView识别滚动

时间:2015-06-26 20:33:26

标签: ios swift uiview uiviewcontroller uiscrollview

我有UIViewController创建自定义UIView对象并将其插入UIScrollViewUIViewControllerUIPanGestureRecognizer附加到每个UIView。即使在通过自定义UIScrollView对象进行触摸时,我仍然可以执行任何操作来允许滚动UIView,同时仍然允许UIPanGestureRecognizers(仅配置为更改x坐标)工作?

这是我的意思截图。蓝色矩形是自定义UIView个对象,白色背景是UIScrollViewenter image description here

非常感谢任何帮助!

1 个答案:

答案 0 :(得分:0)

我明白了!

关于使用UIGestureRecognizerDelegate

在顶部,您可以class ViewController: UIViewController, UIGestureRecognizerDelegate

然后,在类体中添加此方法:

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

最后,在UIView顶部,添加panRecognizer.delegate = selfpanRecognizer是引用UIView的{​​{1}}

的变量