如何始终显示注释标注?如果我们选中地图视图,请不要隐藏。始终显示标注。我怎样才能做到这一点?
提前致谢。
当选择MKAnnotationView
并且视图的canShowCallout
属性设置为YES
时,将显示标注。
当取消选择MKAnnotationView
时,它会被隐藏。这通过点击另一个注释视图或通过点击当前选定的注释视图外部来实现。
作为MKMapView
(符合MKMapViewDelegate
)的代表,当选择并取消选择注释视图时,会告诉您,但是对它做任何事情都为时已晚。
如果您不想取消选择注释视图,则应该继承MKAnnotationView
并覆盖setSelected:animated:
方法并停止取消选择注释视图。
重置注释还会使callout查看状态为true。
[mapView removeAnnotation: currentMarker];
[mapView addAnnotation:currentMarker];
谢谢@Zumry Mohammed这个想法。这个快速的解决方案适合我:
func mapView(_ mapView: MKMapView, didDeselect view: MKAnnotationView) {
guard let ann = view.annotation else {return}
mapView.removeAnnotation(ann)
mapView.addAnnotation(ann)
mapView.selectAnnotation(ann, animated: false)
}