我使用此代码将 MKMapView 转换为 UIImage:
+(UIImage *)imageFromMapView:(MKMapView *)mapView {
BOOL showsUserLocation = mapView.showsUserLocation; //save flag
[mapView setShowsUserLocation:NO]; //hide blue bubble for taking picture
CGRect frame = mapView.frame;
if ([[UIScreen mainScreen] respondsToSelector:@selector(displayLinkWithTarget:selector:)] &&
([UIScreen mainScreen].scale == 2.0)) {
frame.size.width *= 2;
frame.size.height *= 2;
}
// UIGraphicsBeginImageContext(frame.size);
UIGraphicsBeginImageContextWithOptions((frame.size), YES, 0.0);
[mapView.layer renderInContext:UIGraphicsGetCurrentContext()];
UIImage *mapImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
DLog(@"got mapImage size:%@",NSStringFromCGSize(mapImage.size));
[mapView setShowsUserLocation:showsUserLocation];//restore flag
return mapImage;
}
我每次移动 MapView 中心位置时都会调用此方法,因此每一步都会出现黄色气泡和整个动画。这很烦人。
是否可以在没有动画的情况下显示当前用户位置?