UITapGestureRecognizer未在深度视图层次结构中触发 [英] UITapGestureRecognizer not triggered in deep view hiearchy

查看:90
本文介绍了UITapGestureRecognizer未在深度视图层次结构中触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已将UIGestureRecognizer放置在uiview层次结构的深处,但未触发.这是这些视图的总图:

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

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");
}

我正在设置滚动视图的canCancelContentTouches以允许手势传播.

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?

谢谢!

推荐答案

在这种层次结构中,您触摸的点必须位于视图框架和所有父框架之内.响应程序链从滚动视图开始,如果触摸不在滚动视图之内,则在此处停止.然后检查滚动视图的直接子级,依此类推.

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.

如果不是这种情况,我建议编写自己的hittest函数以检查是否击中了最后一帧,然后将其返回.

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.

这篇关于UITapGestureRecognizer未在深度视图层次结构中触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆