On iOS, if a superview#39;s userInteractionEnabled is NO, then all subviews are disabled as well?(在 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,那么所有子视图也会被禁用吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 iOS 上,如果 superview 的 userInteractionEnabled 为 NO,那么所有子视图也会被禁用吗?


基础教程推荐
- android 应用程序已发布,但在 google play 中找不到 2022-01-01
- Android:对话框关闭而不调用关闭 2022-01-01
- 如何在 iPhone 上显示来自 API 的 HTML 文本? 2022-01-01
- Kivy Buildozer 无法构建 apk,命令失败:./distribute.sh -m “kivy"d 2022-01-01
- 如何在 UIImageView 中异步加载图像? 2022-01-01
- 当从同一个组件调用时,两个 IBAction 触发的顺序是什么? 2022-01-01
- UIWebView 委托方法 shouldStartLoadWithRequest:在 WKWebView 中等效? 2022-01-01
- 如何在没有IB的情况下将2个按钮添加到右侧的UINavigationbar? 2022-01-01
- 如何让对象对 Cocos2D 中的触摸做出反应? 2022-01-01
- 在 gmail 中为 ios 应用程序检索朋友的朋友 2022-01-01