开发者

Do I have to implement mapView:regionWillChangeAnimated:on my MKMapview delegate?

Apple's docs tell you this method should be as lightweight as possible, what's a standard use here? Resetting the annotation pins?

Tells the delegate that the region displayed by the map view is about to change.

- (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated

Parameters

mapView

The map view whose visible region is about to change.

animated

If YES, the change to the new region will be animated. If NO, the change will be made immediately.

This method is called whenever the currently displayed map region changes. During scrolling, this method may be called many times to report updates to the map po开发者_Python百科sition. Therefore, your implementation of this method should be as lightweight as possible to avoid affecting scrolling performance.


The problem with this delegate method is "During scrolling, this method may be called many times to report updates to the map position" (so you need IF/THEN or CASE/BREAK, etc to keep it "lightweight").

You don't NEED to use this method at all (not required), but if you do wish to incorporate some sort of functionality (such as removing worthless pins, etc), then example code to keep it lightweight would be:

- (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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜