程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> objective c-多個gestureRecognizer問題

objective c-多個gestureRecognizer問題

編輯:編程綜合問答
多個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;
}

最佳回答:


拿到附加手勢的view後,判斷view的類型,即可相應做出處理

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)recognizer shouldReceiveTouch:(UITouch *)touch {
   UIView *gestureView = recognizer.view;
  if ([gestureView isKindOfClass:[UIImageView class]]) {
         ///...to do 
   }
}
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved