在谷歌地图iOS版
问题描述:
适用于iOS的谷歌地图的文档控制动画时长指出:在谷歌地图iOS版
呼叫的几种方法,让您动画摄像机移动到新位置的一个。您可以使用CoreAnimation控制动画的持续时间。
对于我的生活,我无法弄清楚如何控制动画持续时间。我一直在使用的UIView动画,喜欢尝试:
[UIView animateWithDuration: 5 animations:^{
GMSCameraPosition *camera = [self newCamera];
self.mapView.camera = camera;
} completion:^(BOOL finished) {
}];
而且我看了看CoreAnimation CALayer的动画。但是,我不知道如何将图层动画应用于地图视图。
有人可以指点我正确的方向吗?
答
我找到了答案...你可以通过包装动画的一个控制动画时间*在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];
答
什么贝蒂,使用你只要同样的方法无法知道动画是否已结束。
是的我知道,有一个CATransaction完成块使用这种方法,但它根本不工作! :(
[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat: 1.0f] forKey:kCATransactionAnimationDuration];
[CATransaction setCompletionBlock:^{
// ... whatever you want to do when the animation is complete
}];
[self.googleMapsView animateToCameraPosition:[GMSCameraPosition
cameraWithLatitude:LATITUDE
longitude:LONGITUDE
zoom:ZOOM]];
[CATransaction commit];
我不能使用的MapView:didIdle黑客知道动画已经结束因为如果没有摄像头位置的变化也不会被称为
有谁知道?如何检测animateon已经结束事件
发现了一个线程关心这个(解决): CATransaction completion being called immediately
答
雨燕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()
+0
这很好用 - 谢谢! – 2016-04-21 02:35:58
答
为夫特3.0:
CATransaction.begin()
CATransaction.setValue(1.5, forKey: kCATransactionAnimationDuration)
// your camera code goes here, example:
// mapView.animate(with: update)
CATransaction.commit()
该值(1.5在这种情况下)越大,越慢的动画。
需要:---)谢谢。 – user1007522 2014-08-19 12:22:00