如何始终显示注释标注?如果我们选中地图视图,请不要隐藏。始终显示标注。我怎么能这样做?
谢谢你。
答案 0 :(得分:1)
选择MKAnnotationView
并且视图的canShowCallout
属性设置为YES
时,会显示标注。
当取消选择MKAnnotationView
时隐藏它。这可以通过点击另一个注释视图,或通过点击当前选定的注释视图外部来实现。
作为MKMapView
的代表(符合MKMapViewDelegate
),您会被告知何时选择并取消选择注释视图,但是对它做任何事情都为时已晚。
如果您不想取消选择注释视图,则应该继承MKAnnotationView
并覆盖setSelected:animated:
方法并停止取消选择注释视图。
答案 1 :(得分:1)
重置注释也会使callout看到状态为true。
[mapView removeAnnotation: currentMarker];
[mapView addAnnotation:currentMarker];
答案 2 :(得分:0)
感谢@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)
}
答案 3 :(得分:0)
我只是在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
}