如何防止子视图的剪辑部分仍然接收触摸事件?
我目前正在父视图中剪切一些 UIView,如下图所示:
问题是子视图的剪辑部分(不可见部分)仍在接收触摸事件,直观上,这些事件应该发送到那里可见的其他视图。
我还应该做些什么来实现这种行为,或者这实际上并不是一件容易做的事情?
I'm currently clipping some UIViews within a parent view like in the illustration below:
The problem is that the clipped portions (the invisible portions) of the subviews are still receiving touch events that, intuitively, should be going to the other views visible there.
Is there something else I should be doing to achieve this behavior, or is this not actually an easy thing to do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
发生这种情况是因为本例中的父视图具有
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
的自定义实现,并且它没有执行此边界测试(我现在假设这是默认实现的一部分)。
添加:
围绕该实现中的代码解决了问题。
This was happening because the parent view in this case had a custom implementation of
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event
,and it wasn't performing this bounds test (which I now assume is part of the default implementation).
Adding:
around the code in that implementation solved the problem.