iOS开发之在scrollview上添加点击并解决其子控件的点击无响应(如tableView)

2019独角兽企业重金招聘Python工程师标准>>> hot3.png

- (void)addTap{

    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tap:)];
    tap.delegate = self;
    [_scrollView addGestureRecognizer:tap];
}

- (void)tap:(UITapGestureRecognizer *)tap{

    [self.view endEditing:YES];
}

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch

{
    
    // 假设为UITableViewCellContentView(即点击了tableViewCell),则不截获Touch事件
    if ([NSStringFromClass([touch.view class]) isEqualToString:@"tableViewCell"]) {
        return NO;
    }
    
    return  YES;
    
}

转载于:https://my.oschina.net/wenchengxu123/blog/837473

你可能感兴趣的:(iOS开发之在scrollview上添加点击并解决其子控件的点击无响应(如tableView))