MKMapView上的UIPanGestureRecognizer? [英] UIPanGestureRecognizer on MKMapView?
问题描述
当用户使用地图视图i移动时,我想添加一些逻辑. e.他平移.但是,当我添加手势识别器并想要记录触摸时,什么也没发生.当我在另一个视图控制器中尝试并将识别器添加到控制器的视图中时,它就可以正常工作.
I would like to add some logic when user moves with map view i. e. he does a pan touch. But when I add the gesture recognizer and I want to log the touch, nothing happens. When I try it in another view controller and add the recognizer to controller's view then it works ok.
这是我的代码(地图视图是应用程序委托的属性,因为即使它不可见,我也需要对它进行一些其他操作):
Here's my code (map view is a property of application delegate because I need to do some other things with it even if it isn't visible):
- (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
I use latest iOS 4.2.1
谢谢您的建议.
推荐答案
好吧,因为没人知道,我不得不花一个苹果技术支持来咨询它. ; o)
Ok, because no one knew, I had to spent one Apple technical support consult for it. ;o)
由于MKMapView显然具有与用户交互的识别器,因此您必须遵守UIGestureRecognizerDelegate协议并像这样实现(BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
:
Because MKMapView evidently has its own recognizers to interact with user, you have to adhere to the UIGestureRecognizerDelegate protocol and implement (BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
like this:
- (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;
}
然后它就像一个饰物.
这篇关于MKMapView上的UIPanGestureRecognizer?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!