Please can someone help with a MapView question. I have a custom annotation. When the user taps the annotation, I want it to move up the screen and then disappear. As a test of the animation code (as I am new to this!), I tried the following:
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let pinTapped = view.annotation as? Pin else {return}
guard let pinName = pinTapped.title else { return }
let endFrame = CGRect(x: view.frame.origin.x, y: view.frame.origin.y - self.view.bounds.size.height, width: view.frame.size.width, height: view.frame.size.height)
UIView.animate(withDuration: 3.0, animations: {
view.frame = endFrame
}) { (finished) in
self.mapKitView.removeAnnotation(pinTapped)
}
}
I expected the annotation to slide to the new position over 3 seconds and then disappear. What actually happen is that it immediately moves to the new position, and slides back to the original position, and then disappears. What am I doing wrong?
After you add this animation and customize as you desired,
I hope this solution helped