2011-06-15 47 views
6

如果我更改setRegion中的区域MKMapView,有没有办法设置该动画更改的速度或持续时间?我查看了文档和Google,但没有发现任何内容。MKMapView的setRegion速度

+3

不,不可能改变它们。 – 2011-06-15 02:03:24

+0

你检查了这个:[控制在iOS6 MKMapView的动画速度](http://stackoverflow.com/questions/12785529/controlling-the-animation-speed-of-mkmapview-in-ios6) – theaob 2013-08-16 07:48:04

回答

5

我可以通过编辑对问题的响应设置setRegion动画的持续时间 - Setting the zoom level for a MKMapView - 如下:

#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]; 
    }]; 
} 
+0

好的工作。谢谢! – boraseoksoon 2017-07-12 11:36:03

11

下面是一个易于使用的斯威夫特扩展的情况下,有人绊倒在此未来

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:雨燕3.0版本

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) 
    } 
} 
+0

完美的解决方案!谢谢! – beseder 2016-07-20 08:26:08