iOS 11 中的新 MapKit MarkerAnnotationView 问题
Issue with new MapKit MarkerAnnotationView in iOS 11
我在使用 MKAnnotationView 时遇到问题。我编写了下面嵌入的代码来显示我的 pin,它可以工作,但我从不希望显示字幕,所以我将 var subtitleVisibility: MKFeatureVisibility 写入 .hidden,如我的代码所示。虽然它仍然出现,就像 subtitleVisibility 是 .adaptive ...
怎么了?在此先感谢您的帮助!
弗洛!
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 文档:
The subtitle text is hidden when the marker is not selected. The text is shown when the marker is selected.
我在使用 MKAnnotationView 时遇到问题。我编写了下面嵌入的代码来显示我的 pin,它可以工作,但我从不希望显示字幕,所以我将 var subtitleVisibility: MKFeatureVisibility 写入 .hidden,如我的代码所示。虽然它仍然出现,就像 subtitleVisibility 是 .adaptive ... 怎么了?在此先感谢您的帮助! 弗洛!
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 文档:
The subtitle text is hidden when the marker is not selected. The text is shown when the marker is selected.