对这个荒谬的初级问题表示歉意,但由于某种原因,我无法掌握如何阻止这种情况发生。
当我运行应用程序时,我捏合放大 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/