objective-c - MKMapView 上的 UIPanGestureRecognizer?

标签 objective-c cocoa-touch mkmapview uigesturerecognizer

当用户使用 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/

相关文章:

objective-c - Xcode 'Capture OpenGL ES frame' 响应 'application not found'

ios - 在推特中获取用户名和头像

Objective-C:使用多个参数调用选择器

ios - UIAlertController 按钮位置不一致

ios - 仅向特定行的单元格添加标签

iphone - MKReverseGeocoder 委托(delegate)方法是否在单独的线程上工作?

iphone - 如何设计一个同时适用于横向和纵向模式的 UIview?

objective-c - MagicalRecord——获取请求必须有一个实体

iOS:获取位置之间的距离

iphone - 如何显示来自 MKAnnotationView 的多个标注?