2011-06-15 60 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

相關問題