我有一个包含 TableView 的 UIview。
我希望用户能够在 TableView 中选择项目,并且我希望能够在 TableView 之外的父 View 中识别点击。
如果我向 UIView 添加 Tab 手势识别器,用户将无法在 TableView 中选择项目。
如何完成这个任务?
最佳答案
在这种情况下,您必须向您的 View 添加手势,并且您可以取消手势回调方法,如果触摸发生在 tableview 上,如下所示。
1) 将 TAG 设置为您的 tableview 。 self.tableView.tag = TAG
;
2) 现在如果在 tableview 上触摸则取消手势,如下所示
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch
{
id touchView= touch.view;
if ([touchView isKindOfClass:[UITableView class]] || [touchView isKindOfClass:[UITableViewCell class]] )
{
if ( ((UIView*)touchView).tag == TAG)
return NO;
}
return YES;
}
关于ios - 如何防止手势识别器拦截 child 的消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22525459/