美文网首页
UITapGestureRecognizer不让子视图响应Tap

UITapGestureRecognizer不让子视图响应Tap

作者: MrBan | 来源:发表于2018-07-11 18:50 被阅读0次

    两种方式:

    第一种

    - (CGPoint)locationInView:(nullable UIView*)view;       
    

    用上面的方法判断点击的位置是不是子视图的位置,如果是则可以不处理。

    第二种是给子视图也加一个tap事件,但在实现里不做操作

    UITapGestureRecognizer *tapSuperGesture = [[UITapGestureRecognizer alloc] initWithTarget:self 
    action:@selector(tapSuperView:)];
    tapSuperGesture.delegate = self;
    [self.view addGestureRecognizer:tapSuperGesture];
    
    UITapGestureRecognizer *tapSecondGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapSecondView:)];
    [self.secondView addGestureRecognizer:tapSecondGesture];
      
    - (void)tapSuperView:(UITapGestureRecognizer *)gesture
     {
          //写上你的代码
     }
      
      - (void)tapSecondView:(UITapGestureRecognizer *)gesture
     {
          //不做处理
      }
    

    相关文章

      网友评论

          本文标题:UITapGestureRecognizer不让子视图响应Tap

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