我在使用MKAnnotationView时遇到麻烦。我写了下面嵌入的代码来显示我的密码,该密码可以正常工作,但我从不希望显示字幕,所以我将var subtitleVisibility:MKFeatureVisibility编写为.hidden,如代码所示。尽管仍然显示,就像subtitleVisibility是.adaptive ...
怎么了?在此先感谢您的帮助!
lo!

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

最佳答案

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

MKMarkerAnnotationView subtitleVisibility文档:

未选择标记时,字幕文本被隐藏。选择标记后,将显示文本。

07-28 06:20