如何始终显示地图视图注释标注?

时间:2012-10-15 15:34:50

标签: ios mkmapview mapkit

如何始终显示注释标注?如果我们选中地图视图,请不要隐藏。始终显示标注。我怎么能这样做?

谢谢你。

enter image description here

4 个答案:

答案 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
}