ios - 如何防止手势识别器拦截 child 的消息

标签 ios uigesturerecognizer

我有一个包含 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/

相关文章:

ios - 苹果 watch : Storyboard localization will not work

ios - 如何使用存储的整数属性对核心数据中的数组进行排序?

iphone - viewDidLoad 中的 NSURLRequest 使用缓存数据?

swift - 嵌入式 UITableView 未检测到滑动以删除行手势

ios - 使用手势识别器

objective-c - 具有 iPad 视网膜显示屏的模拟器

ios - 使用 iOS 进行信用卡支付

ios - 带有触摸拦截器的 UIScrollView 用于 contentSize 以控制 subview

ios - 捕获组合的按钮按下和平移手势

ios - UIButtons 上的 UISwipeGestureRecognizer