ios - UIPanGestureRecognizer 从不调用操作方法

标签 ios swift mapkit action uipangesturerecognizer

我正在尝试将 UIPanGestureRecognizer 添加到我的 mapView 但我不明白为什么从未调用操作方法(Swift 2.1 )。

import UIKit
import MapKit

class ViewController: UIViewController, MKMapViewDelegate, CLLocationManagerDelegate, UIGestureRecognizerDelegate
{
    override func viewDidLoad()
    { 
        super.viewDidLoad()

        // other stuff...

        let gestureRecognizer = UIPanGestureRecognizer(target: self, action: "didDragMap:")
        gestureRecognizer.delegate = self
        self.mapView.addGestureRecognizer(gestureRecognizer)
    }

    func didDragMap(sender: UIPanGestureRecognizer)
    {
        // never enter here
    }
}

这里出了什么问题?我有相同的 Objective-C 对应并且它可以工作。

最佳答案

由于 MKMapView 已经处理它自己的手势,因此您需要启用它来监听您的手势。

实现shouldRecognizeSimultaneouslyWithGestureRecognizer并像这样返回 true:

func gestureRecognizer(gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWithGestureRecognizer otherGestureRecognizer: UIGestureRecognizer) -> Bool {
    return true
}

Source

关于ios - UIPanGestureRecognizer 从不调用操作方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36165235/

相关文章:

ios - swift 4: UITableView setSelected 函数在 iPad 上点击两次

ios - indexPath.row 在 UICollectionView 中重新加载

json - swift json 错误 dankogai/swift-json

ios - 给定纬度、经度和航向,我如何确定距离该点 x 米的纬度/经度?

ios - 如何通过 Objective-C 添加自定义图像以替换 iOS MKMapView 中的默认图钉?

objective-c - 如何定义一个 NSArray?

IOS XCode 放置视频文件的正确位置

objective-c - 防止实例变量在内存警告时被清除

ios - 如何在程序运行时禁用(停用)按钮?

ios - MKDirections 不在 iOS map 上显示路线