【问题标题】:mapkit zoom out and then zoom inmapkit 缩小然后放大
【发布时间】:2015-12-17 14:35:22
【问题描述】:

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

但是,它只是缩小,而不是缩小。如果我在缩小时使用 animated:false ,它就可以工作。

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

  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
}

【问题讨论】:

    标签: swift mapkit


    【解决方案1】:

    这段代码应该做你想做的事。 didSelectAnnotationView 在用户点击 pin 时触发。

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

    【讨论】:

      【解决方案2】:

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

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

      【讨论】:

      • 请务必注意,在更改期间可以多次调用此委托。因此,调用此委托并不一定意味着动画实际完成。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多