iOS開發之在scrollview上新增點選並解決其子控制元件的點選無響應(如tableView)
阿新 • • 發佈:2019-01-09
- (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;
}