如何在 MKMapView 中找到 MKAnnotationView?

How to find a MKAnnotationView in MKMapView?

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

selectedPinIndex: Int改变时,我想通过自定义方法更新关联的PinAnnotationView .select()

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) 应该 return 关联的 MKAnnotationView.
https://developer.apple.com/documentation/mapkit/mkmapview/1452512-view