在 iOS 上,如果 superview 的 userInteractionEnabled 为 NO,那么所有子视图也会被禁用吗? [英] On iOS, if a superview's userInteractionEnabled is NO, then all subviews are disabled as well?

查看:22
本文介绍了在 iOS 上,如果 superview 的 userInteractionEnabled 为 NO,那么所有子视图也会被禁用吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为当一个视图被触摸或点击时,它的处理程序首先被调用,然后它的父视图的处理程序被调用(向上传播).

I thought when a view is touched or tapped on, its handler get called first, and then its superview's handler is called (propagate upward).

但是如果超级视图的 userInteractionEnabled 设置为 NO,那么所有子视图和后代也被禁用以进行用户交互是真的吗?如果我们只想禁用主视图但不想禁用子视图怎么办?

But is it true that if the superview's userInteractionEnabled is set to NO, then all subviews and offspring is also disabled for user interaction? What if we want to disable for just the main view but don't want to disable for the subviews?

推荐答案

你不能那样做,

相反,您可以更改视图的排列方式,如下所示:

Instead you would change the arrangment of your views like following:

Main View -> subViews

Container View -> Main View that you want to set as inactive
               -> other views that you want to still be active

所以你当前的主视图和你当前的子视图将成为兄弟,新容器视图的子视图

So your current main view and you current subviews will become siblings, children of a new container view

这篇关于在 iOS 上,如果 superview 的 userInteractionEnabled 为 NO,那么所有子视图也会被禁用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆