在scrollview上添加点击并解决其子控件的点击无响应(如tableView)
- (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;
}
网友评论