(这是我的第一个堆栈溢出问题哈哈)
更新:从此链接 -显示标注之前的中心 MKMapView
我从 Thermometer 实现了解决方案,但是选择和取消选择注释会使我的应用程序看起来像出现故障。
我认为最好的方法是将 callOut(弹出详细信息)延迟几秒钟,以便地图有时间先移动。
这是我的代码:
func mapView(_ mapView: MKMapView, didSelect view: MKAnnotationView) {
guard let annotation = view.annotation else {
return
}
let currentAnnotation = view.annotation as? MapMarker
Global.currentAnnotation = currentAnnotation
findRelatinoshipLines()
if Global.showLifeStoryLines {
var locations = lifeStoryAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.lifeStoryColor
mapView.addOverlay(polyline)
}
if Global.showFatherLines {
var fatherLocations = fatherTreeAnnotations.map { $0.coordinate }
let fatherPolyline = MKPolyline(coordinates: &fatherLocations, count: fatherLocations.count)
Global.finalLineColor = Global.fatherLineageColor
mapView.addOverlay(fatherPolyline)
}
if Global.showMotherLines {
var motherLocations = motherTreeAnnotations.map { $0.coordinate }
let motherPolyline = MKPolyline(coordinates: &motherLocations, count: motherLocations.count)
Global.finalLineColor = Global.motherLineageColor
mapView.addOverlay(motherPolyline)
}
if Global.showSpouseLines {
var locations = spouseAnnotations.map { $0.coordinate }
let polyline = MKPolyline(coordinates: &locations, count: locations.count)
Global.finalLineColor = Global.spouseColor
mapView.addOverlay(polyline)
}
if Global.zoomChange == true {
Global.zoomChange = false
} else {
let currentRegion = mapView.region
let span = currentRegion.span
let location = currentAnnotation!.coordinate
let region = MKCoordinateRegion(center: location, span: span)
DispatchQueue.main.asyncAfter(deadline: .now() + 1.0) {
mapView.setCenter(annotation.coordinate, animated: true)
//mapView.setRegion(region, animated: true)
}
}
}
继续:
基本上,我正在开发一个家庭谱系应用程序,该应用程序在地图上显示亲戚的事件。
当我单击注释(事件)时,详细信息(事件属于谁、何时何地等)会在上方弹出一个信息按钮以显示所选人员。
我将其设置为设置MKMapView
区域,以便每次单击新注释时所选注释居中。
问题是,当我单击屏幕边缘的事件时,我的注释标题/描述会居中弹出,以便它适合我的屏幕,因为它不知道我计划将地图视图重新居中说注释。
我想知道是否有任何方法可以使标题/描述直接显示在所选注释上方的中心,这样当我移动地图时,所有内容都居中并适合屏幕。
以下是我正在谈论的一些屏幕截图: