MKMapView 上的 UIPanGestureRecognizer?
我想在用户使用地图视图移动时添加一些逻辑,即他进行平移触摸。但是当我添加手势识别器并且我想记录触摸时,什么也没有发生。当我在另一个视图控制器中尝试它并将识别器添加到控制器的视图中时,它可以正常工作。
这是我的代码(地图视图是应用程序委托的一个属性,因为即使它不可见,我也需要用它做一些其他事情):
- (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 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!");
}
I use latest iOS 4.2.1
Thanks for any advice.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好吧,因为没有人知道,我不得不为此花费了一位苹果技术支持咨询费用。 ;o)
因为 MKMapView 显然有自己的识别器来与用户交互,所以你必须遵守 UIGestureRecognizerDelegate 协议并实现
(BOOL)gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer:
像这样:然后它就像一个魅力。
Ok, because no one knew, I had to spent one Apple technical support consult for it. ;o)
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:Then it works like a charm.
雨燕5
Swift 5