iOS 11中新的MapKit MarkerAnnotationView问题

时间:2017-09-26 08:50:12

标签: ios swift xcode mapkit ios11

我遇到MKAnnotationView问题。我编写了下面嵌入的代码来显示我的pin,它有效,但我从不想要显示字幕,所以我写了var subtitleVisibility:MKFeatureVisibility to .hidden,如我的代码所示。虽然它仍然显示,就像副标题可见性是.adaptive ... 怎么了?在此先感谢您的帮助! FLO!

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
    if #available(iOS 11.0, *) {
        guard let annotation = annotation as? Bike else { return nil }

        let identifier = "marker"
        var view: MKMarkerAnnotationView

        if let dequeuedView = mapView.dequeueReusableAnnotationView(withIdentifier: identifier)
            as? MKMarkerAnnotationView {
            dequeuedView.annotation = annotation
            view = dequeuedView
        } else {
            view = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: identifier)
            view.canShowCallout = false
            view.markerTintColor = self.userBike.markerTintColor
            view.glyphImage = self.userBike.glyphImage
        }
        view.subtitleVisibility = MKFeatureVisibility.hidden
        view.animatesWhenAdded = true
        return view
    } else {
        let annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "pin-annotation")

        annotationView.animatesDrop = true
        annotationView.canShowCallout = true
        return nil
    }
}

1 个答案:

答案 0 :(得分:1)

subtitleVisibility设置为false时,它仅会在未选择标记时停止显示文本。选择标记后,字幕将显示。

MKMarkerAnnotationView subtitleVisibility文档:

  

未选择标记时隐藏字幕文本。选择标记时会显示文本。