开发者

UITapGestureRecognizer not triggered in deep view hiearchy

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 > UIVie开发者_运维百科w > 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜