GMSMapView animateToCameraPosition放大 - 缩小动画 [英] GMSMapView animateToCameraPosition zoom in - zoom out animation

查看:527
本文介绍了GMSMapView animateToCameraPosition放大 - 缩小动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在iOS(Swift)和Android中使用Google地图服务。在android中,地图视图有一个名为 animatreCamera 的方法,它具有一个动画,其中的动作具有缩小 - 放大效果(如果两个摄影机具有相同的缩放,地图视图将缩小移动的第一部分,然后放大第二部分)。我想用iOS中的 GMSMapView 实现这种效果,我尝试了以下方法: animateToCameraPosition animateToLocation animateWithCameraUpdate moveCamera 并将相机设置为 mapView.camera = GMSCameraPosition(target:location,zoom:15,bearing:0,viewingAngle:0)并且它们都没有这个动画。如果可能的话,移动相机时我该如何实现这个动画? 解决方案

我认为没有直接的方法可以存档相同的动画在Google Maps iOS SDK中。



解决方法可以使用iOS的 dispatch_after 方法,首先您可以定义方法来延迟你想要的秒数:

  func delay(#seconds:Double,completion:() - > ){
let popTime = dispatch_time(DISPATCH_TIME_NOW,Int64(Double(NSEC_PER_SEC)* seconds))
$ b dispatch_after(popTime,dispatch_get_main_queue()){
completion()
}
}

然后你可以缩小你的相机,移动到一个位置,然后放大延迟方法:

 延迟(秒:0.5) {() - > ()in 
var zoomOut = GMSCameraUpdate.zoomTo(kGMSMinZoomLevel)
mapView.animateWithCameraUpdate(zoomOut)

delay(seconds:0.5,{() - >()in
var vancouver = CLLocationCoordinate2DMake(49.26,-123.11)
var vancouverCam = GMSCameraUpdate.setTarget(vancouver)
mapView.animateWithCameraUpdate(vancouverCam)

delay(seconds:0.5,
var zoomIn = GMSCameraUpdate.zoomTo(kGMSMaxZoomLevel)
mapView.animateWithCameraUpdate(zoomIn)

})
})$ b中的{() - &
$ b $ / code>

您使用您自己的缩放值,我使用 kGMSMinZoomLevel kGMSMaxZoomLevel 这里。


I am using Google maps services in iOS (Swift) and Android. In android, the map view has a method called animatreCamera that has an animation in which the movement has a "zoom out - zoom in" effect (if both cameras have the same zoom, the map view will zoom out the first part of the movement and then zoom in the second part). I want to achieve this effect with the GMSMapView in iOS, I have tried te following methods: animateToCameraPosition, animateToLocation, animateWithCameraUpdate, moveCamera and setting the camera by mapView.camera = GMSCameraPosition(target: location, zoom: 15, bearing: 0, viewingAngle: 0) and none of them have this animation. If possible, how can I achieve this animation when moving the camera?

解决方案

I think there is no direct way you can archive the same animation in the Google Maps iOS SDK.

A workaround can use iOS's dispatch_after method, first you can define a method to delay how many seconds you want:

func delay(#seconds: Double, completion:()->()) {
    let popTime = dispatch_time(DISPATCH_TIME_NOW, Int64( Double(NSEC_PER_SEC) * seconds ))

    dispatch_after(popTime, dispatch_get_main_queue()) {
        completion()
    }
}

Then you can zoom out your camera, move to a location, then zoom in with the delay method:

delay(seconds: 0.5) { () -> () in
    var zoomOut = GMSCameraUpdate.zoomTo(kGMSMinZoomLevel)
    mapView.animateWithCameraUpdate(zoomOut)

    delay(seconds: 0.5, { () -> () in
        var vancouver = CLLocationCoordinate2DMake(49.26,-123.11)
        var vancouverCam = GMSCameraUpdate.setTarget(vancouver)
        mapView.animateWithCameraUpdate(vancouverCam)

        delay(seconds: 0.5, { () -> () in
            var zoomIn = GMSCameraUpdate.zoomTo(kGMSMaxZoomLevel)
            mapView.animateWithCameraUpdate(zoomIn)

        })
    })
}

You use your own zoom value, I use kGMSMinZoomLevel and kGMSMaxZoomLevel here.

这篇关于GMSMapView animateToCameraPosition放大 - 缩小动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆