ios - Mapkit - Swift4 - 如何禁用自动缩放

标签 ios swift mapkit zooming

对这个荒谬的初级问题表示歉意,但由于某种原因,我无法掌握如何阻止这种情况发生。

当我运行应用程序时,我捏合放大 map (或缩小,或导航远离我的位置),应用程序总是会将我拉回到设定的高度和我的位置。我不希望发生这种情况,只希望获得缩放到任意级别并在不被中断的情况下移动的体验。

有什么想法吗?

这是我的 VC 的代码片段:

let regionRadius: CLLocationDistance = 2000
func centerMapOnLocation(location: CLLocation) {
let coordinateRegion = MKCoordinateRegionMakeWithDistance(location.coordinate, regionRadius, regionRadius)

    mapView.setRegion(coordinateRegion, animated: true)
}


func locationManager(_ manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {

    let location = locations[0]

    let center = location.coordinate
    let span = MKCoordinateSpan(latitudeDelta: 0.05, longitudeDelta: 0.05)
    let region  = MKCoordinateRegion(center: center, span: span)

    mapView.setRegion(region, animated: true)
    mapView.showsUserLocation = true

}

感谢您的帮助

最佳答案

位置管理器委托(delegate)方法可以随时频繁调用。因此您需要停止更新位置。

func locationManager(manager: CLLocationManager, didUpdateLocations locations: [CLLocation]) {
    manager.stopUpdatingLocation()
    manager.delegate = nil

    let location = locations[0]
    ...
}

关于ios - Mapkit - Swift4 - 如何禁用自动缩放,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50881759/

相关文章:

mapkit - calloutAccessoryControlTapped 未调用/触发

ios - 如何在 MapKit 中为引脚注释命名?

ios - 应用中存在多个广告实例

Swift ObjectMapper 嵌套循环

ios - 快速将 UnsafeMutableRawPointer 转换为 String(utf8)

ios - NSPredicate 使用数组作为过滤器

iOS map 标记和当前位置未显示

ios - 如何跟踪项目的当前查看者数量?

iphone - 带有框架、图标和图像的自定义 MKAnnotationView

iphone - 使用启用优化的 XCode Instruments Time Profiler