SetRegion speed for MKMapView

If I changed the scope in setRegion for MKMapView , is there a way to set the speed or duration of the change in this animation? I looked through the documentation and google but found nothing.

+7
source share
2 answers

And here is a simple Swift extension in case someone stumbles upon this in the future

 import MapKit extension MKMapView { func animatedZoom(zoomRegion zoomRegion:MKCoordinateRegion, duration:NSTimeInterval) { MKMapView.animateWithDuration(duration, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 10, options: UIViewAnimationOptions.CurveEaseIn, animations: { self.setRegion(zoomRegion, animated: true) }, completion: nil) } } 

UPD: Swift 3 version

 extension MKMapView { func animatedZoom(zoomRegion:MKCoordinateRegion, duration:TimeInterval) { MKMapView.animate(withDuration: duration, delay: 0, usingSpringWithDamping: 0.6, initialSpringVelocity: 10, options: UIViewAnimationOptions.curveEaseIn, animations: { self.setRegion(zoomRegion, animated: true) }, completion: nil) } } 
+12
source

I managed to set the duration of the setRegion animation by editing the answer to the question - Setting the zoom level for MKMapView - as follows:

 #import <MapKit/MapKit.h> @interface MKMapView (ZoomLevel) - (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(NSUInteger)zoomLevel animated:(BOOL)animated; @end #import "MKMapView+ZoomLevel.h" @implementation MKMapView (ZoomLevel) #define ANIMATION_DURATION 0.5 - (void)setCenterCoordinate:(CLLocationCoordinate2D)centerCoordinate zoomLevel:(NSUInteger)zoomLevel animated:(BOOL)animated { MKCoordinateSpan span = MKCoordinateSpanMake(0, 360/pow(2,zoomLevel)*self.frame.size.width/256); [MKMapView animateWithDuration:ANIMATION_DURATION animations:^{ [self setRegion:MKCoordinateRegionMake(centerCoordinate, span) animated:YES]; }]; } 
+5
source

All Articles