Here is my method :
private func animateCamera(lat: Double, long: Double, zoom: Float) {
DispatchQueue.main.async {
CATransaction.begin()
CATransaction.setValue(1, forKey: kCATransactionAnimationDuration)
let camera = GMSCameraPosition.camera(withLatitude: lat, longitude: long, zoom: zoom)
self.mapView.animate(to: camera)
CATransaction.commit()
}
}
Here is how I call it :
animateCamera(lat: obs.position.latitude, long: obs.position.longitude, zoom: 7)
The zoom animation is working on an iPhone X.
On the other hand, on an iPhone 7, the zoom animation isn't centered on my destination point when it's finished (the lat/lon passed as parameters).
Is it because of different screen resolution ?
How should I handle this ?
Try using the long-form initializer on the camera position method and a more modern approach to setting the duration of your CATransaction
:
private func animateCamera(lat: Double, long: Double, zoom: Float) {
DispatchQueue.main.async {
CATransaction.begin()
CATransaction.setAnimationDuration(1)
CATransaction.setAnimationTimingFunction(CAMediaTimingFunction(controlPoints: 0.25, 0.75, 0.25, 1)) // you can add a timing curve too btw
self.mapView.animate(to: GMSCameraPosition.camera(withLatitude: lat, longitude: long, zoom: zoom, bearing: self.mapView.camera.bearing, viewingAngle: self.mapView.camera.viewingAngle))
CATransaction.commit()
}
}
This produces the same result in all of my simulators.