我正在编写一个应用程序,它使用地图跟踪用户并跟踪所采用的路径。在会话结束时,用户按下地图缩小的按钮以显示整个路径并捕获地图的屏幕截图以供以后使用。目前,我的应用程序发送动画命令,然后在动画有机会平移之前继续拍摄屏幕截图。如何在不使用延迟的情况下缓解此问题?
启动动画的代码后跟捕获屏幕的代码如下:
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)
答案 0 :(得分:0)
使用GMSMapViewDelegate来处理回调。一种方法是让类实现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)
}