更改地图中心后标注在错误位置打开

Callout is opened in wrong location after changing the map center

当用户 select 从 table 中获取项目时,我将地图的中心更改为 selected 项目的位置,并且 select 匹配以编程方式注释。这会导致标注标注在地图上打开。

mapView.centerCoordinate = itemCoordinate
mapView.selectAnnotation(itemAnnotation, animated: true)    

我的问题是callout是在地图之前的地方打开的,好像是先打开callout然后地图移动(没有移动callout)

有什么解决办法吗?

您可以尝试 select 在像这样的小延迟后添加注释:

let dispatchTime: dispatch_time_t = dispatch_time(DISPATCH_TIME_NOW, Int64(0.1 * Double(NSEC_PER_SEC)))
dispatch_after(dispatchTime, dispatch_get_main_queue()) { () -> Void in
   mapView.selectAnnotation(itemAnnotation, animated: true)
}

或者select没有动画的注释也应该有效:

mapView.selectAnnotation(itemAnnotation, animated: false)