当用户使用 map View i 移动时,我想添加一些逻辑。 e.他做了一个平底锅触摸。但是当我添加手势识别器并且我想记录触摸时,什么也没有发生。当我在另一个 View Controller 中尝试它并将识别器添加到 Controller 的 View 中时,它可以正常工作。
这是我的代码( map View 是应用程序委托(delegate)的一个属性,因为即使它不可见,我也需要用它做一些其他事情):
- (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
感谢您的建议。
最佳答案
好吧,因为没人知道,我不得不为此花费了一次 Apple 技术支持咨询。 ;o)
因为 MKMapView 显然有自己的识别器来与用户交互,所以你必须遵守 UIGestureRecognizerDelegate 协议(protocol)并像这样实现 (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;
}
然后它就像一个魅力。
关于objective-c - MKMapView 上的 UIPanGestureRecognizer?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5005597/