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

  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;
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容