2011-01-30 62 views
2

苹果的文档告诉你这种方法应该尽可能的轻量化,这里的标准用法是什么?重置注释引脚?我是否必须在我的MKMapview委托上实现mapView:regionWillChangeAnimated:?

告诉代表由地图视图中显示的区域 即将 变化。

-(无效)的MapView:(的MKMapView *)的MapView regionWillChangeAnimated:(BOOL)动画

参数

MapView的
地图视图,其可见光区是 即将改变。

动画
如果是,换到新的区域 将动画。如果否,则立即更改 。

只要 当前显示的地图区域 发生更改,就会调用此方法。在滚动期间,可能会多次调用此方法 以报告地图位置的更新 。 因此,您执行此 方法时应尽可能轻量级,以避免影响滚动 的性能。

回答

0

与此委托方法的问题是“在滚动,这种方法可称为多次上报更新的地图位置”(所以你需要IF/THEN或CASE/BREAK等,以保持它的“轻量级“)。你不需要使用这个方法(不是必需的),但是如果你想要合并某种功能(例如去除无用的引脚等),那么保持它轻量级的示例代码将是:

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated{ 
if(!animated){ 
//Instantaneous change, which means you probably did something code-wise, so you should have handled anything there, but you can do it here as well. 

} else { 
//User is most likely scrolling, so the best way to do things here is check if the new region is significantly (by whatever standard) away from the starting region 

CLLocationDistance *distance = [mapView.centerCoordinate distanceFromLocation:originalCoordinate]; 
if(distance > 1000){ 
//The map region was shifted by 1000 meters 
//Remove annotations outsides the view, or whatever 
//Most likely, instead of checking for a distance change, you might want to check for a change relative to the view size 
} 

} 

} 
+0

哦所以注释视图不会自动纠正其位置? – quantumpotato 2011-01-31 13:31:28

相关问题