简体   繁体   English

动画 GMSMapView

[英]Animating GMSMapView

I tried all the animation methods provided by google maps.我尝试了谷歌地图提供的所有动画方法。 But I fail to animate the zoomlevel of map view.但是我无法为地图视图的缩放级别设置动画。 I have tried mapView.animateToZoom(15).我试过 mapView.animateToZoom(15)。 Also还有

UIView.animateWithDuration(5.0, animations: {
                    let zoomIn = GMSCameraUpdate.zoomTo(15)
                    self.mapView.animateToZoom(15)
                })

But I fail to achieve the animation.但我无法实现动画。 I also followed GMSMapView animateToCameraPosition zoom in - zoom out animation我也跟着GMSMapView animateToCameraPosition zoom in - zoom out animation

But no hope.但没有希望。 Can anyone help please?有人可以帮忙吗?

After a lot of struggle I managed to animate the GMSMapView: Here is the code for the reference:经过一番努力,我设法为 GMSMapView 设置动画:这是参考代码:

mapView.camera = GMSCameraPosition.cameraWithLatitude(58.998400,longitude: 10.035604, zoom: 1)


        CATransaction.begin()
        CATransaction.setValue(2.0, forKey: kCATransactionAnimationDuration)
        let city = GMSCameraPosition.cameraWithLatitude(58.998400,longitude: 10.035604, zoom: 15)
        self.mapView.animateToCameraPosition(city)
        CATransaction.commit()

Update for swift 5 Swift 5 的更新

CATransaction.begin()
CATransaction.setValue(1.0, forKey: kCATransactionAnimationDuration)
let city = GMSCameraPosition.camera(withTarget:  CLLocationCoordinate2D(latitude, longitude:logitude), zoom: 16)
self.mapView.animate(to: city)
CATransaction.commit()

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

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