用于iOS的Google文档指出:
调用几种方法之一,允许您动画相机移动到一个新的位置。您可以使用CoreAnimation控制动画的持续时间。
对于我的生活,我不知道如何控制动画的持续时间。我尝试过使用UIView动画,例如:
[UIView animateWithDuration: 5 animations:^{
GMSCameraPosition *camera = [self newCamera];
self.mapView.camera = camera;
} completion:^(BOOL finished) {
}];
我看过CALayer在CoreAnimation中的动画。但是,我不知道如何将图层动画应用到地图视图中。
有人能给我指个正确的方向吗?
发布于 2013-03-27 15:43:36
我找到了答案。可以通过在CATransaction中包装动画*方法之一来控制动画持续时间,如下所示:
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat: 1.0f] forKey:kCATransactionAnimationDuration];
// change the camera, set the zoom, whatever. Just make sure to call the animate* method.
[self.mapView animateToCameraPosition: [self newCamera]];
[CATransaction commit];
发布于 2016-12-06 18:02:57
Swift 3.0:
CATransaction.begin()
CATransaction.setValue(1.5, forKey: kCATransactionAnimationDuration)
// your camera code goes here, example:
// mapView.animate(with: update)
CATransaction.commit()
值越大(本例中为1.5),动画速度就越慢。
发布于 2016-01-27 21:49:33
Swift 2.0
CATransaction.begin()
CATransaction.setValue(NSNumber(float: 1.0), forKey: kCATransactionAnimationDuration)
// change the camera, set the zoom, whatever. Just make sure to call the animate* method.
CATransaction.commit()
https://stackoverflow.com/questions/15662148
复制相似问题