我想設置我的MKMapView
,這樣當我按住地圖2秒鐘時,用戶當前位置就會出現一個別針。Swift 3 MKMapView - 在長按時添加pin /註釋
以下是我在我的viewDidLoad
:
let gestureRecognizer = UILongPressGestureRecognizer(target: self, action:(Selector(("longPress:"))))
gestureRecognizer.minimumPressDuration = 2.0
gestureRecognizer.delegate = self
map.addGestureRecognizer(gestureRecognizer)
在我的ViewController類的底部
然後,我有以下幾點:
func longPress(gestureRecognizer: UILongPressGestureRecognizer) {
let coordinate = map.centerCoordinate
let annotation = MKPointAnnotation()
annotation.coordinate = coordinate
map.addAnnotation(annotation)
}
當我跑地圖上的應用程序,並按下2秒鐘,應用程序崩潰。控制檯說
型NSException的未捕獲的異常
和
無法識別的選擇發送到實例0x7f89f0c02ad0
結束,我不知道爲什麼。感謝您提供任何指導。
http://stackoverflow.com/questions/24681275/how-to-do-a-long-press-in-swift – 2017-02-13 00:16:23