控制Google Maps for iOS中的animation持续时间

Google Maps for iOS的文档指出:

调用几种方法之一,可以让相机移动到新的位置。 您可以使用CoreAnimation控制animation的持续时间。

对于我的生活,我无法弄清楚如何控制animation的持续时间。 我曾尝试使用UIViewanimation,如:

[UIView animateWithDuration: 5 animations:^{ GMSCameraPosition *camera = [self newCamera]; self.mapView.camera = camera; } completion:^(BOOL finished) { }]; 

我已经看了CoreAnimation中的CALayeranimation。 但是,我不知道如何将图层animation应用到地图视图。

有人能指点我吗?

我find了答案…您可以通过在CATransaction中包装一个animate *方法来控制animation持续时间,如下所示:

  [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]; 

对于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),animation越慢。

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() 

使用您在那里提供的相同方法的一个可怜的事情是无法知道animation是否已经结束。

是的,我知道,有一个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 hack来知道animation已经结束了, 因为如果没有摄像头位置变化,它将不会被调用。

任何人都知道如何检测animateon已结束事件?

find了一个关于这个(解决)的线程 : 立即调用CATransaction完成