我将 MKMapView
包裹在 ViewRepresentable
中
public struct MapView: UIViewRepresentable {
我想创建一个像这样工作的动作回调:
MapView().onAnnotationTapped { annotation in
}
在MapView
中我已经定义了
@inlinable public func onAnnotationTapped(site: (AnnotationView) -> ()) -> some View {
return self
}
但是如何从协调员那里提供AnnotationView
?
public class MapViewCoordinator: NSObject,mkmapviewdelegate {
var mapView: MapView
init(_ control: MapView) {
self.mapView = control
}
public func mapView(_ mapView: MKMapView,didSelect view: MKAnnotationView) {
/// How to send from here to the MapView function?
}
}