How to get touches when parent view has userInteractionEnabled set to NO in iOS(当父视图在 iOS 中将 userInteractionEnabled 设置为 NO 时如何进行触摸)
问题描述
当父视图的 userInteractionEnabled=NO 时,其子视图将不接受触摸事件,即使它们的 userInteractionEnabled 属性设置为 YES.
When the parent view has userInteractionEnabled=NO, its subviews will not accept touch events even if their userInteractionEnabled property is set to YES.
有没有办法在子视图中仍然获取触摸事件?
Is there any way to still get touch events in subviews?
推荐答案
要获得一个让触摸通过但让其子视图处理触摸的视图,让该视图上的 userInteractionEnabled 为 YES,然后使用以下代码段:
To get a view to let touches pass-through but give its subviews handle touches, let userInteractionEnabled on that view to YES and, instead, use this snippet:
-(id)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
id hitView = [super hitTest:point withEvent:event];
if (hitView == self) return nil;
else return hitView;
}
来源:http://cocoaheads.tumblr.com/post/2130871776/ignore-touches-to-uiview-subclass-but-not-to-its
这篇关于当父视图在 iOS 中将 userInteractionEnabled 设置为 NO 时如何进行触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:当父视图在 iOS 中将 userInteractionEnabled 设置为 NO 时如何进行触摸


- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- android 4中的android RadioButton问题 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01