问题描述
我有一个自定义的PinAnnotation
和PinAnnotationView
。我有一个旋转木马,selectedPinIndex
是活动卡。 PinAnnotation
有一个index: Int
当selectedPinIndex: Int
更改时,我想通过自定义方法.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)
,该方法应返回关联的MKAnnotationView
。
https://developer.apple.com/documentation/mapkit/mkmapview/1452512-view