我有一个标签,我想在地图视图中显示,但标签只应在用户缩放到特定缩放级别时显示。所以我想做以下事情:
if (mapView.camera.altitude >= 5) {
//display label here
}
我喜欢每次用户缩放时检查和更新缩放级别。所以我认为ViewDidAppear将是这段代码的最佳位置。
提前致谢。
答案 0 :(得分:1)
您应该通过以下代码处理它。
-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated
{
NSUInteger zoomLevel = MAXIMUM_ZOOM; // MAXIMUM_ZOOM is 20 with MapKit
MKZoomScale zoomScale = mapView.visibleMapRect.size.width / mapView.frame.size.width; //MKZoomScale is just a CGFloat typedef
double zoomExponent = log2(zoomScale);
zoomLevel = (NSUInteger)(MAXIMUM_ZOOM - ceil(zoomExponent));
if(zoomLevel > 5 && labelNotAdded)
{
//Add the label
}
else
{
//Remove the label
}
}