In iOS 10.1, swift 3 I have added some annotations (cars) on my Apple Map. I made them move by using animate(withDuration duration: TimeInterval, animations: @escaping () -> Void)
.
I want to show information when we tap on the cars, but the event mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView)
is not work when the cars are moving. I guess that only works when the cars don't move (I have tried).
Then I add a UITapGestureRecognizer
into Map to detect tapped coordinate and check it is near by the cars' coordinate or not. That works. However, it only works when we tap near by the cars. If we tap inside the cars, it does not work.
I hope you can give me a solution for this case. Thanks a lot.
EDIT
In func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView?
before return a MKAnnotationView
I set property isUserInteractionEnabled
false. The UITapGestureRecognizer
works perfectly.
But I want to know how to select Animating annotation. Do you have any solutions?