【发布时间】:2020-07-10 14:50:06
【问题描述】:
我有一些从前一个 segue 的准备功能中获得的位置的地图视图。我在视图中有一个 for in 循环确实加载了,以便我可以进行注释并显示它们。这一切工作正常,但是当我单击前一个视图控制器中的显示地图按钮时,它会将我带到我的地图视图,并且 mapView 会自动放大很多到第一个注释。这可能是个问题,因为我希望用户看到所有位置。
我的问题是,如何阻止地图的初始缩放?
下面是我的 viewDidLoad 代码。
顺便说一句,bins 是我在核心数据中的实体,mapView 是我的 IBOutlet 变量,连接到情节提要中的 Map Kit。
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)
}
}
}
)}
}`
【问题讨论】: