如何暂停动画代码?
How to pause code for animation?
我正在编写一个应用程序,该应用程序使用地图来跟踪用户并追踪所走的路径。在会话结束时,用户按下一个按钮,地图在该按钮上缩小以显示整个路径并捕获地图的屏幕截图以供以后使用。目前,我的应用程序发送动画命令,然后在动画有机会平移之前继续截取屏幕截图。如何在不使用延迟的情况下缓解这种情况?
启动动画的代码和捕获屏幕的代码如下:
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 来处理回调。一种方法是让 class 实现 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)
}
我正在编写一个应用程序,该应用程序使用地图来跟踪用户并追踪所走的路径。在会话结束时,用户按下一个按钮,地图在该按钮上缩小以显示整个路径并捕获地图的屏幕截图以供以后使用。目前,我的应用程序发送动画命令,然后在动画有机会平移之前继续截取屏幕截图。如何在不使用延迟的情况下缓解这种情况?
启动动画的代码和捕获屏幕的代码如下:
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 来处理回调。一种方法是让 class 实现 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)
}