我有一个地图视图的一些位置,我是从前面的segue的准备功能。我在视图中加载了一个for in循环,这样我就可以进行注释并显示它们。这一切都很好,但当我单击上一个视图控制器中的show Map按钮时,它会将我带到我的地图视图,并且mapView会自动放大到第一个注释上。这可能是一个问题,因为我想让用户看到所有的位置。
我的问题是,我如何阻止地图中的这种初始缩放发生?
下面是我的viewDidLoad代码。
顺便说一下,IBOutlet是核心数据中的实体,mapView是连接到storyboard中地图工具包的bins变量。
override func viewDidLoad() {
super.viewDidLoad()
mapView.delegate = self
for bin in bins {
let geoCoder = CLGeocoder()
geoCoder.geocodeAddressString(bin.address ?? "", completionHandler: { placemarks, error in
if let error = error {
print(error)
return
}
if let placemarks = placemarks {
// Get the first placemark
let placemark = placemarks[0]
let annotation = MKPointAnnotation()
annotation.title = bin.type
if let location = placemark.location {
annotation.coordinate = location.coordinate
// Display the annotation
self.mapView.showAnnotations([annotation], animated: true)
self.mapView.selectAnnotation(annotation, animated: true)
}
}
}
)}
}`
发布于 2020-07-10 23:25:22
这一行:self.mapView.showAnnotations([annotation], animated: true)
缩放地图以显示单个注释,而不是所有注释。您需要创建一个包含所有批注的数组,并在创建所有批注后进行显示。
https://stackoverflow.com/questions/62836854
复制相似问题