本文介绍了当父视图在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;
}
资料来源:
这篇关于当父视图在iOS中将userInteractionEnabled设置为NO时,如何进行触摸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!