我有一张 map ,在这张 map 上,我有 10 个自定义注释图钉。所有图钉都具有相同的自定义图像。当我点击一个图钉时,我需要更改所有其他 9 个注释的图像。可以更改点击的图钉图像,但我需要保持原样,并且我需要更改所有其他图钉图像。
我尝试使用 map mapView.annotations
获取所有注释,并尝试查找选定的注释并更改其他图像但无法管理。以及如何做的想法?
提前致谢。
最佳答案
遵循 MKMapViewDelegate
协议(protocol)然后:
func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
let selectedAnnotation = view.annotation
for annotation in mapView.annotations {
if let annotation = annotation as? MKAnnotation where !annotation.isEqual(selectedAnnotation) {
// do some actions on non-selected annotations in 'annotation' var
}
}
如果您想稍后处理所有注释,您也可以在这里保存所选注释以备后用。
关于swift - 如何使用 Swift 在 mapkit 上更改未选择的注释图钉图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31934110/