我正在尝试将一组引脚的颜色更改为蓝色,并将另一组引脚的颜色更改为红色。我在这里关注了一个问题,这让我了解到引脚确实会改变颜色。而且我当前的位置也变成了一个图钉。此外,图钉也从新 Logo 变为旧 Logo (实际上是图钉的图像)。有没有办法让图钉保持像新 Logo /图像一样,并且还可以正常显示我当前的位置,即蓝色脉冲点。以及将一组引脚更改为蓝色,而其余引脚保持红色?
请帮忙! 下面是我的代码:
class MyPointAnnotation : MKPointAnnotation {
var pinTintColor: UIColor?
}
class ViewController: UIViewController, MKMapViewDelegate {
@IBOutlet var map: MKMapView!
override func viewDidLoad() {
super.viewDidLoad()
map.delegate = self
let anx = MyPointAnnotation()
anx.coordinate = CLLocationCoordinate2D(latitude: -36.56795, longitude: 176.56432)
anx.pinTintColor = .red
let any = MyPointAnnotation()
any.coordinate = CLLocationCoordinate2D(latitude: -36.54322, longitude: 176.43221)
any.pinTintColor = .blue
map.addAnnotation(anx)
map.addAnnotation(any)
}
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
var annotationView = mapView.dequeueReusableAnnotationView(withIdentifier: "myAnnotation") as? MKPinAnnotationView
if annotationView == nil {
annotationView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "myAnnotation")
} else {
annotationView?.annotation = annotation
}
if let annotation = annotation as? MyPointAnnotation {
annotationView?.pinTintColor = annotation.pinTintColor
}
return annotationView
}
}
最佳答案
But also my current location turns into a pin.
在mapView:viewFor...
方法中添加以下代码:
func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? {
if annotation is MKUserLocation {
return nil
}
关于ios - 更改 MKmapView 中图钉的颜色会将新图钉图像以及当前位置变成旧图钉图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49142228/