Superview 忽略 UserInteractionEnabled = NO?
我有一个子视图,它以动画方式显示在屏幕上,当它在屏幕上时,我希望超级视图(在我的例子中,背景中的视图)忽略触摸事件。 我尝试了一切,但它不起作用。
有没有办法“强制”超级视图停止接收触摸事件?
谢谢!
I have a subview thats goes onto the screen animated, and when it is on the screen, I want the superview (in my case, the view in the background), to ignore touch events.
I tried everything but it does not work.
Is there any way to 'force' the superview to stop receiving touch events?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
当您说超级视图时,我假设您指的是动画视图的超级视图。 Apple 的文档对于 userInteractionEnabled 的描述非常不具体,但我认为如果将其设置为 false,它将禁用特定视图上的触摸事件,但不会禁用其子视图上的触摸事件。我建议你递归地进行。下面是一个代码示例,您可以使用它来禁用/启用视图上的所有触摸事件:
然后您可以在超级视图
[self setInteraction:NO onView:[self superview]]
上调用此代码。当然,这也会禁用您的触摸事件,因为您在超级视图上递归地禁用它们。当然,您始终可以重新启用触摸事件[self setUserInteractionEnabled:NO]
。另外,Apple 的 UIView 类参考提到一些 UI 组件会重写此方法:
When you say the superview, I assume you you mean the animating view's superview. Apple's documentation is very unspecific about
userInteractionEnabled
, but I think that if you set it to false, it disables touch events on the specific view, but not on its subviews. I would suggest that you do it recursively. Here is an example of code that you could use to disable/enable ALL touch events on a view:You could then call this on your superview
[self setInteraction:NO onView:[self superview]]
. This would, of course, disable your touch events as well, since you are disabling them recursively on your superview. Of course you can always re-enable your touch events[self setUserInteractionEnabled:NO]
.Also, Apple's UIView Class Reference mentions that some UI components override this method: