ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

UITapGestureRecognizer 和 UICollectionView/UITableView等点击事件冲突问题

2021-07-22 11:34:25  阅读:14  来源: 互联网

标签:gestureRecognizer UICollectionView UITapGestureRecognizer 点击 isDescendantOfView 


在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;
}

 

标签:gestureRecognizer,UICollectionView,UITapGestureRecognizer,点击,isDescendantOfView,
来源: https://www.cnblogs.com/huangzs/p/15043312.html

专注分享技术,共同学习,共同进步。侵权联系[admin#icode9.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有