我有一个使用 MapKit 的应用程序。
我在调整地图大小后计算当前缩放。
通过定义(来自MKGeometry.h
文件)
MKZoomScale provides a conversion factor between MKMapPoints and screen points.
When MKZoomScale = 1, 1 screen point = 1 MKMapPoint. When MKZoomScale is
0.5, 1 screen point = 2 MKMapPoints.
所以,我是这样计算的:
- (void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
CGSize screenSize = mapView.bounds.size;
MKMapRect mapRect = mapView.visibleMapRect;
MKZoomScale zoomScale = screenSize.width * screenSize.height / (mapRect.size.width * mapRect.size.height);
}
计算zoomScale
符合定义(我已经检查过)。
我还在方法中在我的 mapView 上绘制了一个叠加层
-(void)drawMapRect:(MKMapRect)mapRect zoomScale:(MKZoomScale)zoomScale inContext:(CGContextRef)context
问题是,我的计算zoomScale
不等于系统传递给这个方法的那个。我希望它们是相等的,因为drawMapRect:
在调整大小之后调用(实际上,调整大小会导致调用此方法)。
这里有什么问题?
我也尝试使用
currentZoomScale = mapView.bounds.size.width / mapView.visibleMapRect.size.width;
, 建议在这里,但这currentZoomScale
也不等于传递给drawMapRect:
。