I tested this problem with a simple demo application on the beta versions of iOS 6 and iOS 7. It turns out that displaying a map does not actually always liven up the transition between regions. It depends on how far the regions are. For example, the transition from Paris to London is not lively. But if you first zoom out a little and then move to London, it will be animated.
The documentation says:
animated: specify YES if you want the map view to display a transition to a new region or NO if you want the map to focus on the specified area immediately.
But, as we saw, we cannot rely on animation. We can only show the map view that the transition should be animated. MapKit decides whether the animation is appropriate. It tells the delegate if the transition will be animated in -(void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated .
To constantly animate a change in a region in all cases, you first need to plunge into the intermediate area. Let A be the region of the current display, and B be the region of the target. If there is an intersection between regions, you can go directly. (Convert MKCoordinateRegion to MKMapRect and use MKMapRectIntersection to find the intersection). If there is no intersection, calculate area C that spans both areas (use MKMapRectUnion and MKCoordinateRegionForMapRect ). Then first go to region C and into regionDidChangeAnimated go to region B.
Code example:
MKCoordinateRegion region = _destinationRegion; MKMapRect rect = MKMapRectForCoordinateRegion(_destinationRegion); MKMapRect intersection = MKMapRectIntersection(rect, _mapView.visibleMapRect); if (MKMapRectIsNull(intersection)) { rect = MKMapRectUnion(rect, _mapView.visibleMapRect); region = MKCoordinateRegionForMapRect(rect); _intermediateAnimation = YES; } [_mapView setRegion:region animated:YES];
-(void)mapView:(MKMapView *)mapView regionDidChangeAnimated:(BOOL)animated { if (_intermediateAnimation) { _intermediateAnimation = NO; [_mapView setRegion:_destinationRegion animated:YES]; } }
This helper method is taken from here.
MKMapRect MKMapRectForCoordinateRegion(MKCoordinateRegion region) { MKMapPoint a = MKMapPointForCoordinate(CLLocationCoordinate2DMake( region.center.latitude + region.span.latitudeDelta / 2, region.center.longitude - region.span.longitudeDelta / 2)); MKMapPoint b = MKMapPointForCoordinate(CLLocationCoordinate2DMake( region.center.latitude - region.span.latitudeDelta / 2, region.center.longitude + region.span.longitudeDelta / 2)); return MKMapRectMake(MIN(ax,bx), MIN(ay,by), ABS(ax-bx), ABS(ay-by)); }
WWDC 2013 Session 309 Entering a map in Vista explains how to make such complex transitions in iOS 7.