使UIGestureRecognizer接收在子视图上开始的触摸 [英] Make UIGestureRecognizer to receive touches started on subviews
问题描述
我在一个 UIView
上附加了自定义的 UIGestureRecognizer
,该UIView几乎覆盖了整个屏幕.该视图包含一个小的子视图,该子视图也需要接收正常的触摸.
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.
即使希望触摸子视图,我也要把gestureRecognizer放在首位并能正常工作.如何将在此子视图上开始的所有触摸都转发给其父视图,以使我的gestureRecognizer能够完成其工作?
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?
推荐答案
我找到了解决方案!实际上很简单.
I found the solution! It's actually quite simple.
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
// Forward this message up the responder chain
[super touchesBegan:touches withEvent: event];
}
在子视图的 touchBegan
中对super的调用就足够了.在此博客上找到它
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
这篇关于使UIGestureRecognizer接收在子视图上开始的触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!