美文网首页
IOS 子视图不响应父视图的手势识别器

IOS 子视图不响应父视图的手势识别器

作者: 多啦A梦的百宝袋 | 来源:发表于2016-10-08 15:25 被阅读370次
  UIView *bgView = [[UIView alloc]initWithFrame:CGRectMake(0, 304, SCREEN_WIDTH, SCREEN_HEIGHT)];
    bgView.backgroundColor = COLOR_A(0, 0, 1, 0.5);
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(hiddenBgView:)];
    tap.delegate = self;
    [bgView addGestureRecognizer:tap];

本类继承 UIGestureRecognizerDelegate
重写UIGestureRecognizerDelegate代理方法

#pragma mark 手势代理
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{//_tab1,_tab2,_tab3 不需要响应的子view
    if ([touch.view isDescendantOfView:_tab1] ||[touch.view isDescendantOfView:_tab2]||[touch.view isDescendantOfView:_tab3]) {
        return NO;
    }
    return YES;
}

相关文章

网友评论

      本文标题:IOS 子视图不响应父视图的手势识别器

      本文链接:https://www.haomeiwen.com/subject/exbuyttx.html