美文网首页
UITapGestureRecognizer 和 UITable

UITapGestureRecognizer 和 UITable

作者: 学无止境666 | 来源:发表于2021-11-29 15:41 被阅读0次
    icon_home_arrow_down@3x.png
    UITableView 解决
    /*1.遵守UIGestureRecognizerDelegate的协议*/
    @interface ****ViewController ()<UIGestureRecognizerDelegate>
    @end
    
    /*2.Create GR对象,并且当前controller成为代理*/
    -(void)viewDidLoad{
        UITapGestureRecognizer *tapGr = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClicked:)];
        tapGr.delegate = self;
        [self.view addGestureRecognizer:tapGr];
    }
    
    /*3.实现这个代理方法*/
    #pragma mark Delegate for the gestureRecognizer
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
        if ([NSStringFromClass([touch.view class]) isEqualToString:@"UITableViewCellContentView"]) {
            return NO;
        }
        return YES;
    }
    
    
    UICollectionView 处理
    #pragma mark -UIGestureRecognizerDelegate
    //判断是否是collectionCell 是的话不响应tap手势
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldReceiveTouch:(UITouch *)touch{
        if ([touch.view isDescendantOfView:self.collectVc]) {
            if ([self.collectVc indexPathForItemAtPoint:[touch locationInView:self.collectVc]]) {
                return NO;
            }
        }
        return YES;
    }
    

    做个记录

    相关文章

      网友评论

          本文标题:UITapGestureRecognizer 和 UITable

          本文链接:https://www.haomeiwen.com/subject/ohrlxrtx.html