如何 link MapView 中的注释到它的调用 pin
How to link an annotation in MapView to its calling pin
Swift 4 iOS 11.x
学习了 mapViews 和注释,我可以完全理解我想做的一些功能。
我创建了一个 mapView,并用一个按钮向其添加了注释,目前一切顺利。我希望按钮是一个删除图钉,所以它看起来像这样。
现在,当我点击蓝色的无条目时,我希望它也删除它所连接的黑色引脚。但是如何将注释的 link 追踪到它的引脚。我通过按钮和附件视图收到了回电。我可以查找视图的标题并找到 link,但肯定有更好的方法。
您需要使用此方法 func mapView(_ mapView: MKMapView,annotationView view: MKAnnotationView,calloutAccessoryControlTapped control: UIControl)
of MKMapViewDelegate
类似这样
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
//Here you have the annotation that was selected
let selectedAnnotation = view.annotation
//Do whatever you need here
}
Swift 4 iOS 11.x
学习了 mapViews 和注释,我可以完全理解我想做的一些功能。
我创建了一个 mapView,并用一个按钮向其添加了注释,目前一切顺利。我希望按钮是一个删除图钉,所以它看起来像这样。
现在,当我点击蓝色的无条目时,我希望它也删除它所连接的黑色引脚。但是如何将注释的 link 追踪到它的引脚。我通过按钮和附件视图收到了回电。我可以查找视图的标题并找到 link,但肯定有更好的方法。
您需要使用此方法 func mapView(_ mapView: MKMapView,annotationView view: MKAnnotationView,calloutAccessoryControlTapped control: UIControl)
of MKMapViewDelegate
类似这样
func mapView(_ mapView: MKMapView, annotationView view: MKAnnotationView,
calloutAccessoryControlTapped control: UIControl) {
//Here you have the annotation that was selected
let selectedAnnotation = view.annotation
//Do whatever you need here
}