Hello there,
Is there a way to animate MGLAnnotation coordinate changes using Core Animation?
Currently, I'm doing it like this without any animations:
func changeCoordinate() {
myAnnotation.coordinate = model.getCurrentCoordinate()
mapView.setNeedsLayout()
mapView.layoutIfNeeded()
}
I would love to do something like this:
func changeCoordinate() {
UIView.animate(withDuration: 1.5, animations: {
self.myAnnotation.coordinate = self.model.getCurrentCoordinate()
self.mapView.setNeedsLayout()
self.mapView.layoutIfNeeded()
})
}
Bumping this issue.
I don't need a final solution right now. Somebody please just comment whether animation of annotations has been attempted, and if so, what is the best way to do it at the moment.
Thanks in advance!
Petr
Hi @petrmanek. Currently, an MGLAnnotationView can be implicitly animated using Core Animation. This would allow you to describe an animation that should occur for your view when its annotation coordinate changes like in changeCoordinate() above.
Closing this put please feel free to contact our support team if you have additional questions about how to use our iOS SDK.
I went back and forth with MapBox support and got 2 takeaways to share:
MGLPointAnnotation class.Then this code should work:
var myAnnotation = MGLPointAnnotation() // or a subclass
// ...
func changeCoordinate() {
UIView.animate(withDuration: 1.5, animations: {
// Here Core Animation calls MapBox using an implicit animation.
self.myAnnotation.coordinate = self.model.getCurrentCoordinate()
})
}
Thanks @petrmanek. You may be interested in following this issue about an issue with using UIView animation blocks (such as the one in https://github.com/mapbox/mapbox-gl-native/issues/8378#issuecomment-289450780) when the annotation location change takes the annotation view out of the viewport.
this is good, but I cannot click on annotatiun during core animation :-(
@djdance would you mind opening a new ticket? Thanks!
Most helpful comment
I went back and forth with MapBox support and got 2 takeaways to share:
MGLPointAnnotationclass.Then this code should work: