简体   繁体   English

如何减慢Google Maps for iOS中的相机动画位置?

[英]How to slow the camera animation location in Google Maps for iOS?

In the Google Maps app for iOS, when you tap the My Location button, the camera slowly pans to your current location from whatever location you are currently at. 在适用于iOS的Google地图应用中,当您点按“我的位置”按钮时,相机会从您当前所在的位置慢慢平移到当前位置。

Following the Google's developer documentation I have implemented a similar method like the one shown when a user taps a button: 根据Google的开发者文档,我实现了类似于用户点击按钮时显示的方法:

- (void) animateToCameraPosition:   (GMSCameraPosition *)  cameraPosition;

This is similar to my code: 这与我的代码类似:

 GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: lat
                                                        longitude: long zoom: 17];

[googleMapView animateToCameraPosition:camera];

It works, and the camera pans to whatever location I want based on the coordinates I specified. 它工作正常,相机根据我指定的坐标平移到我想要的任何位置。 However, the panning is really fast, instantaneous in fact. 然而,事实上,平移真的很快,很快。

I want the camera to slowly pan from whatever location I'm at to the location specified, as demonstrated in Google Maps. 我希望相机从我所在的任何位置慢慢平移到指定位置,如Google地图所示。

How can I achieve this? 我怎样才能做到这一点? Thanks 谢谢

Basically, you need to put CATransaction around your code. 基本上,您需要在代码周围放置CATransaction

[CATransaction begin];
[CATransaction setValue:[NSNumber numberWithFloat: YOUR_SPEED] forKey:kCATransactionAnimationDuration];
GMSCameraPosition *camera = [GMSCameraPosition cameraWithLatitude: lat
                                                    longitude: long zoom: 17];
[googleMapView animateToCameraPosition: camera];
[CATransaction commit];

The [NSNumberWithFloat: YOUR_SPEED] will define the duration of your animation. [NSNumberWithFloat: YOUR_SPEED]将定义动画的持续时间。

for swift 3 对于斯威夫特3

CATransaction.begin()
CATransaction.setValue(Int(YOUR_SPEED), forKey: kCATransactionAnimationDuration)
// YOUR CODE IN HERE
CATransaction.commit()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM