2015-12-17 128 views
1

我放大了地图。当用户选择一个新的poi时,我想缩小(动画),并在动画放大到新的poi后。mapkit缩小,然后放大

但是,它只是缩小,不在。如果我使用动画:缩小时它是假的它正在工作。

如何放大地图完成缩小动画?

func centerMapOnLocation(location: CLLocation) { 

    //Är kartan inzoomad.. zooma ut först. 
    if isZoomed 
    { 
     let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, 
      20000, 20000) 
     OverviewMap.setRegion(coordinateRegion, animated: false) 

    } 

    let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, 
     regionRadius * 4.0, regionRadius * 4.0) 
    OverviewMap.setRegion(coordinateRegion, animated: true) 
    isZoomed=true 
} 

回答

0

您需要确保一个setRegion动画在调用下一个setRegion之前完成。

查看MKmapViewDelegateregionDidChangeAnimated方法。这将允许您对setRegion动画的完成做出反应并链接下一个setRegion动画。

+0

重要的是要注意,这个委托可以在更改期间多次调用。因此,调用这个委托并不一定意味着动画实际完成。 – C6Silver

1

此代码应该做你想做的。 didSelectAnnotationView在用户点击某个引脚时触发。

var zoomingIn = false 
var zoomingAnnotation:MKAnnotation 

func mapView(mapView: MKMapView, didSelectAnnotationView view: MKAnnotationView) 
{ 
    let pin = view as! MKPinAnnotationView 
    zoomInOnPin(pin.annotation!) 
} 

func zoomInOnPin(annotation:MKAnnotation) { 
    let zoomOutRegion = MKCoordinateRegion(center: mapView.region.center, span: MKCoordinateSpan(latitudeDelta: 0.09, longitudeDelta: 0.09)) 
    zoomingIn = true 
    zoomingAnnotation = annotation 
    mapView.setRegion(zoomOutRegion, animated: true) 
} 

func mapView(mapView: MKMapView, regionDidChangeAnimated animated: Bool) { 
    if let annotation = zoomingAnnotation where zoomingIn == true { 
     zoomingIn = false 
     let region = MKCoordinateRegion(center: zoomingAnnotation.coordinate, span: MKCoordinateSpan(latitudeDelta: 0.07, longitudeDelta: 0.07)) 
     mapView.setRegion(region, animated: true) 
    } 
}