如何在MKMapView中找到MKAnnotationView?

问题描述

我有一个自定义的PinAnnotationPinAnnotationView。我有一个旋转木马,selectedPinIndex是活动卡。 PinAnnotation有一个index: Int

selectedPinIndex: Int更改时,我想通过自定义方法.select()

更新关联的PinAnnotationView
func updateSelectedPin(_ mapView: MKMapView,selectedPinIndex: Int?) {
    if selectedPinIndex != nil {
        guard let annotations = mapView.annotations as? [PinAnnotation] else {
            return
        }
        
        
        // how do I find the associated PinAnnotationView for this annotation?
        // let annovationView = 
    }
}

解决方法

您的mapView应该具有方法view(for: MKAnnotation),该方法应返回关联的MKAnnotationView
https://developer.apple.com/documentation/mapkit/mkmapview/1452512-view

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...