UITapGestureRecognizer 在深度视图层次结构中未触发
我已将 UIGestureRecognizer 放置在我的 uiview 层次结构深处,但它没有被触发。这是视图的一般图:
UIScrollView > UI视图> UI视图> UI视图> UIView
最后一个视图具有手势识别器:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.userInteractionEnabled = TRUE;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[self addGestureRecognizer:tap];
[tap release];
}
return self;
}
- (void)tap:(UIGestureRecognizer *)recognizer {
NSLog(@"tap");
}
我正在设置滚动视图的 canCancelContentTouches
以允许手势传播。
当我用手势将视图移动到滚动视图的正下方时,它就可以工作了。有人可以解释为什么它在深层层次结构中不起作用吗?
谢谢!
I have placed a UIGestureRecognizer deep within my uiview hierarchy but it is not being trigger. Here is a general map of the views:
UIScrollView > UIView > UIView > UIView > UIView
The last view has the gesture recognizer:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
self.userInteractionEnabled = TRUE;
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tap:)];
[self addGestureRecognizer:tap];
[tap release];
}
return self;
}
- (void)tap:(UIGestureRecognizer *)recognizer {
NSLog(@"tap");
}
I am setting the canCancelContentTouches
of the scrollview to allow gestures to propagate through.
When I moved the view with the gesture to directly underneath the scrollview it works. Can someone explain why it does not work in a deep hierarchy?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在这样的层次结构中,您触摸的点必须位于视图框架和所有父框架内。响应者链从滚动视图开始,如果触摸位于滚动视图之外,它将在那里停止。然后它检查滚动视图的直接子级等等。
如果不是这种情况,我建议编写自己的 hittest 函数来检查最后一帧是否被命中并返回。
In such a hierarchy the point you touch must be in within the views frame and all parent frames. The responder chain starts at the scrollview, and if the touch is outside of the scrollview it stops there. Then it checks the direct children of the scrollview and so on.
If that's not the case i suggest writing your own hittest function to check if the last frame is hit and return it then.