我在網上看到很多關於它的問題,特別是在StackOverflow上。 我測試了很多給出的答案,但在我的情況下,沒有任何工作。shouldReceiveTouch不叫
我的類實現了協議UIGestureRecognizerDelegate
:
@interface CDMapViewController : CDViewController <UIGestureRecognizerDelegate>
下面的方法是從Xcode的自動完成在@implentation寫我的班級
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer
shouldReceiveTouch:(UITouch *)touch {
NSLog(@"not called");
return NO;
}
我有正確初始化的UIGestureRecognizer在第一方法,正確請撥打第二,第三和第四種方法:
- (void)initGestureOnMap {
UIGestureRecognizer *gestureRecognizer = [[UIGestureRecognizer alloc] init];
gestureRecognizer.delegate = self;
[self.view addGestureRecognizer:gestureRecognizer];
}
- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesBegan:touches withEvent:event];
gesture_dragging = NO;
}
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
gesture_dragging = YES;
}
- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
if (gesture_dragging || [touches count] != 1) return;
/* bla bla bla */
}
...它不記錄 - 不叫...爲什麼?
手勢識別器旨在代替'touchesBegan:'和所有這些方法。你通常只需要實現一個或另一個。 – 2013-04-11 11:45:32