在gestureRecognizer方法中,利用isDescendantOfView来判断当前点击区域是否是collectionView/tableView,若是,则返回NO,忽略该手势的点击事件,否则返回YES。
先添加代理 UIGestureRecognizerDelegate ,再判断触摸点在触摸视图时禁用此 tap
#pragma mark - UIGestureRecognizerDelegate - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch { if ([touch.view isDescendantOfView:self.collectionView]) { return NO; } return YES; }