Ios 如何暂停动画代码?

Ios 如何暂停动画代码?,ios,google-maps,animation,swift,screenshot,Ios,Google Maps,Animation,Swift,Screenshot,我正在编写一个应用程序,它使用地图跟踪用户并跟踪所走的路径。在会话结束时,用户按下一个按钮,地图将缩小以显示整个路径,并捕获地图的屏幕截图供以后使用。目前,我的应用程序发送动画命令,然后在动画有机会完成之前继续拍摄屏幕截图。如何在不使用延迟的情况下缓解此问题 启动动画的代码以及捕获屏幕的代码如下所示: var bounds = GMSCoordinateBounds(coordinate: CLLocationCoordinate2DMake(latitudes[0], longditudes[

我正在编写一个应用程序,它使用地图跟踪用户并跟踪所走的路径。在会话结束时,用户按下一个按钮,地图将缩小以显示整个路径,并捕获地图的屏幕截图供以后使用。目前,我的应用程序发送动画命令,然后在动画有机会完成之前继续拍摄屏幕截图。如何在不使用延迟的情况下缓解此问题

启动动画的代码以及捕获屏幕的代码如下所示:

var bounds = GMSCoordinateBounds(coordinate: CLLocationCoordinate2DMake(latitudes[0], longditudes[0]), coordinate: CLLocationCoordinate2DMake(latitudes[(latitudes.count)-1], longditudes[(longditudes.count)-1]))
var camera = mapView.cameraForBounds(bounds, insets:UIEdgeInsetsZero)
mapView.animateToCameraPosition(camera)

UIGraphicsBeginImageContext(mapView.frame.size)
mapView.layer.renderInContext(UIGraphicsGetCurrentContext())
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
使用函数来处理回调。一种方法是让类实现GMSMapViewDelegate协议,并将屏幕截图代码移动到
-(void)mapView:idleAtCameraPosition:

func initiateAnimation() {
  var bounds = GMSCoordinateBounds( ... )
  var camera = mapView.cameraForBounds(bounds, insets:UIEdgeInsetsZero)
  mapView.delegate = self
  mapView.animateToCameraPosition(camera)
}

func mapView(view: GMSMapView, idleAtCameraPosition position: GMSCameraPosition) {
  UIGraphicsBeginImageContext(mapView.frame.size)
  mapView.layer.renderInContext(UIGraphicsGetCurrentContext())
  let image = UIGraphicsGetImageFromCurrentImageContext()
  UIGraphicsEndImageContext()
  UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil)
}

谢谢你让我注意到这个函数,我要去好好看看GMSMapViewDelegate的其余部分。谢谢你的帮助!