您如何始终显示注释标注,即当您选择地图视图时不隐藏它们?

重置注释也将使标注视图状态为真。
[mapView removeAnnotation: currentMarker];
[mapView addAnnotation:currentMarker];
MKAnnotationView选中AN并将视图的canShowCallout属性设置为时,显示标注YES。
然后在MKAnnotationView取消选择时将其隐藏。这通过点击另一个注释视图或通过在当前选定的注释视图之外点击来实现。
作为MKMapView(conforming to MKMapViewDelegate) 的代表,您会在选择和取消选择注释视图时被告知,但为时已晚。
如果您不想取消选择注释视图,则应子类MKAnnotationView化并覆盖该setSelected:animated:方法并停止取消选择注释视图。
谢谢@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)
}
我只是在 viewFor 注释方法上将 isSelected 属性设置为 true ,仅此而已。
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
let annotationV = MKAnnotationView(annotation: annotation, reuseIdentifier: nil)
annotationV.image = UIImage(named: "ZeusSurveyMarkerTaskIcon", in: Bundle(for: ZsurveysGeofenceLocationMapView.self), compatibleWith: nil)
annotationV.canShowCallout = true
annotationV.isSelected = true
return annotationV
}