2015-05-09 56 views
-1

我有一个194x427(InterfaceBuilder大小)的MKMapView,我试图让地图区域显示一张大约3米的地图。但我看起来最小的地图区域是162米。如何放大或变换地图,使其更加丰富起来?我尝试应用CGAffineTransform,但它似乎并不正确;地图总是会重新更新并撤销任何变换。我该如何做这项工作?谢谢。为什么MKMapView不能显示地图视图只有3m到10m?

回答

0

基本上解决的办法是把MKMapView放到一个子视图中,我称之为mapClipper。然后,我们要做的就是捕捉的MKMapView的图像,并将其添加为子视图mapClipper,上的MKMapView本身之上,所以现在我们看到的是图像:

UIGraphicsBeginImageContextWithOptions(_mapView.bounds.size, NO, [UIScreen mainScreen].scale); 
[_mapView.layer renderInContext:UIGraphicsGetCurrentContext()]; 
UIImage *viewImage = UIGraphicsGetImageFromCurrentImageContext(); 
UIGraphicsEndImageContext(); 
UIImageView *mapImage = [[UIImageView alloc] initWithImage:viewImage]; 
mapImage.tag = 666; 
UIView *oldMapImage = [_mapClipper viewWithTag:666]; 
[oldMapImage removeFromSuperview]; 
[_mapClipper addSubview:mapImage]; 

我们放大地图不止MKMapView通常会允许什么,只需使用CGAffineTransformScale来修改mapImage.transform的缩放比例即可。给定一个比例因子,您可以根据地图实际表示的每点相对于您想要的比例来确定比例因子(称为scaleFactor),请使用如下所示:

mapImage.transform = CGAffineTransformScale(mapImage.transform,scaleFactor, scaleFactor);