UITapGestureRecognizer不让子视图响应Tap

2018-07-11  本文已影响0人  MrBan

两种方式:

第一种

- (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
 {
      //不做处理
  }
上一篇 下一篇

猜你喜欢

热点阅读