我正在尝试将 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
}
关于ios - UIPanGestureRecognizer 从不调用操作方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36165235/