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 时如何进行触摸
基础教程推荐
- 如何从 logcat 中删除旧数据? 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- iOS4 创建后台定时器 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
