如何使用Swift更改MapKit上未选择的注释图钉图像 [英] How to change non selected annotation pin images on mapkit with Swift

查看:72
本文介绍了如何使用Swift更改MapKit上未选择的注释图钉图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一张地图,在这张地图上,我有10个自定义注释图钉.所有引脚具有相同的自定义图像.当我单击图钉时,我需要更改所有其他9个注释的图像.可以更改单击的图钉的图像,但我需要保持原样,并且需要更改所有其他图钉的图像.

I have a map and on this map, I have 10 custom annotation pins. All pins have the same custom image. When I click on a pin, I need to change all the other 9 annotation's images. it's possible to change the clicked pin's image but I need to keep as it is and I need to change all other pins images.

我尝试使用地图mapView.annotations获取所有注释,并尝试查找选定的注释并更改其他图像,但无法对其进行管理.想知道怎么做?

I tried to get all annotations with Map mapView.annotations and tried to find selected annotations and change other images but couldn't manage it. And idea how to do it?

谢谢.

推荐答案

遵循MKMapViewDelegate协议,然后:

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

如果要稍后处理所有注释,还可以保存选定的注释以供以后使用.

Also you can save the selected annotation for later use here, if you want to process all annotations in another moment.

这篇关于如何使用Swift更改MapKit上未选择的注释图钉图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆