使 UIGestureRecognizer 接收在子视图上启动的触摸
我将一个自定义 UIGestureRecognizer
附加到一个几乎填满整个屏幕的 UIView
上。该视图包含一个小子视图,它也需要接收正常的触摸。
问题:在此子视图上启动的触摸不会由附加到其父视图的识别器处理。
我希望gestureRecognizer成为第一优先级并且即使子视图被触摸也能工作。我怎样才能将在此子视图上启动的所有触摸转发到其父视图,以便我的gestureRecognizer可以完成其工作?
I attached a custom UIGestureRecognizer
to one UIView
which fills almost the whole screen. This view contains a small subview which needs to receive normal touches as well.
Problem: Touches started on this subview are not handled by the recognizer attached to its parent.
I want the gestureRecognizer to be first priority and work even if the subview is touched. How can I forward all touches started on this subview to its parent as well in order that my gestureRecognizer can do its job?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我找到了解决方案!其实很简单。
只需在子视图的
touchBegan
中调用 super 即可。在这个博客上找到的
允许父视图接收子视图捕获的事件
I found the solution! It's actually quite simple.
The call to super in
touchBegan
of the subview is all it takes.Found it on this blog
Allow superview to recieve events caught by subview