2 mapmapm MapMapM 于 2013.06.26 17:14 提问

多个gestureRecognizer问题

在parentClass(继承自UIView)中:

[self addGestureRecognizer:_tapGesture]; // _tapGesture is UITapGestureRecognizer, with delegate on parentClass

在someClass中:

[_myImageView addGestureRecognizer:_imageViewGestureRecognizer]; // _imageViewGestureRecognizer is UITapGestureRecognizer, with delegate on someClass

问题:我每次点击ImageView时,两个手势都会被触发。我只要_imageViewGestureRecognizer 触发。

试过:

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldReceiveTouch:(UITouch *)touch {
   UIView *gestureView = recognizer.view;
   CGPoint point = [touch locationInView:gestureView];
   UIView *touchedView = [gestureView hitTest:point withEvent:nil];
   if ([touchedView isEqual:_imageViewGestureRecognizer]) {
     return NO;
   }

   return YES;
}

1个回答

zhanglei5415
zhanglei5415   Rxr 2013.06.27 11:43
已采纳

拿到附加手势的view后,判断view的类型,即可相应做出处理

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldReceiveTouch:(UITouch *)touch {
   UIView *gestureView = recognizer.view;
  if ([gestureView isKindOfClass:[UIImageView class]]) {
         ///...to do 
   }
}
Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!