如何使用Swift中的MapKit让用户在地图中将注释从一个位置拖动到另一个位置?我将注释视图设置为可拖动,当我的地图视图委托创建注释视图时,如下所示:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var v : MKAnnotationView! = nil
if annotation is MyAnnotation {
let ident = "bike"
v = mapView.dequeueReusableAnnotationView(withIdentifier:ident)
if v == nil {
v = MyAnnotationView(annotation:annotation, reuseIdentifier:ident)
}
v.annotation = annotation
v.isDraggable = true
}
return v
}
Run Code Online (Sandbox Code Playgroud)
其结果是,用户可以排序的拖动注释-但只有一次.之后,注释变得无法拖动,更糟糕的是,注释现在不再"属于"地图 - 当滚动/平移地图时,注释仍然保持而不是滚动/平移地图.我究竟做错了什么?