UIPanGestureRecognizer在MKMapView?

我想添加一些逻辑,当用户移动地图视图,即他做一个平底锅。 但是,当我添加手势识别器,我想logging触摸,没有任何反应。 当我在另一个视图控制器尝试它,并将识别器添加到控制器的视图,那么它工作正常。

这里是我的代码(地图视图是应用程序委托的属性,因为即使它不可见,我也需要做一些其他的事情):

- (void)viewDidLoad { ... UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(showPan)]; [appDelegate.mapView addGestureRecognizer:panGesture]; [panGesture release]; } - (void)showPan { NSLog(@"pan!"); } 

我使用最新的iOS 4.2.1

感谢您的任何build议。

好吧,因为没有人知道,我不得不花了一个苹果技术支持咨询。 ; O)

因为MKMapView显然有自己的识别器来与用户交互,所以你必须遵守UIGestureRecognizerDelegate协议并实现(BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:像这样:

 - (void)viewDidLoad { ... UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(showPan)]; panGesture.delegate = self; [appDelegate.mapView addGestureRecognizer:panGesture]; [panGesture release]; } - (void)showPan { NSLog(@"pan!"); } - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { return YES; } 

那么它就像一个魅力。