xcode - 确定当前增量/跨度是多少

标签 xcode swift mapkit

点击注释时,我将该注释置于 map 中心,没问题。问题是,如果用户放大或缩小了原始缩放级别,我会想要那个缩放级别。

这就是我将 map 居中的方式。但同样,我如何获得当前跨度?

func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {

    let span = MKCoordinateSpanMake(1.1, 1.1) //Get current span?
    let region = MKCoordinateRegion(center: view.annotation.coordinate, span: span)
    mapView.setRegion(region, animated: true)

}

最佳答案

您可以简单地请求当前的 MKMapView.region 并在其上设置一个新的中心坐标:

func mapView(mapView: MKMapView!, didSelectAnnotationView view: MKAnnotationView!) {
    var region = mapView.region  // get the current region
    region.center = view.annotation.coordinate

    mapView.setRegion(region, animated: true)    
}

关于xcode - 确定当前增量/跨度是多少,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26863311/

相关文章:

ios - 单元格未出现在 UITableView 中 - Swift 3

swift - Xcode Siri 意图 : How to pass a variable from Intent Handler to IntentUI ViewController without including it in the response

ios - X代码 7.3.1, "Undefined symbols for architecture arm64"

ios - Swift:在init的基类版本中调用子类函数

Swift Tableview 刷新错误

ios - 如何更改 MapView 中 MKUserLocation 注释的显示优先级?

ios - 使静态单元格快速执行操作

ios - 使 UIImage 填满整个导航栏

swift 4 : error: extraneous argument label

ios - 带本地搜索的 MapView