我正在Xcode中创建一个应用程序。我在mapView上有一个不同的引脚,但我蚂蚁改变其中一个引脚,成为当前位置(“雷达”外观)图标,显示不同的颜色。我怎么能这样做?
以下是我目前的代码:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
let pin = mapView.view(for: annotation) as? MKPinAnnotationView ?? MKPinAnnotationView(annotation: annotation, reuseIdentifier: nil)
pin.pinTintColor = #colorLiteral(red: 0.8823529412, green: 0.1647058824, blue: 0.1333333333, alpha: 1)
return pin
} else {
let annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "pin")
annotationView.pinTintColor = #colorLiteral(red: 0.007843137255, green: 0.3803921569, blue: 0.8156862745, alpha: 1)
return annotationView
}
}
答案 0 :(得分:0)
而不是:
if annotation is MKUserLocation {
let pin = mapView.view(for: annotation) as? MKPinAnnotationView ?? MKPinAnnotationView(annotation: annotation, reuseIdentifier: nil)
pin.pinTintColor = #colorLiteral(red: 0.8823529412, green: 0.1647058824, blue: 0.1333333333, alpha: 1)
return pin
// ...
只需返回nil
,MapKit
将自动显示用户位置图标:
if annotation is MKUserLocation {
return nil
} else {
// ...