與此委託方法的問題是「在滾動,這種方法可稱爲多次上報更新的地圖位置」(所以你需要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
}
}
}
哦所以註釋視圖不會自動糾正其位置? – quantumpotato 2011-01-31 13:31:28