我有一个TableView,用于在单击单元格时显示MapView注释标注。
在iOS 10中,我可以使用以下代码将MapView居中显示在注释上,然后显示它的标注:
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let location = locations[indexPath.item]
mapView.setCenter(location.coordinate, animated: true)
mapView.selectAnnotation(location, animated: true)
}
locations
是一个MKAnnotation
数组。在iOS 10上,我正在使用MKPinAnnotationView
,而在iOS 11上则使用MKMarkerAnnotationView
。
iOS 11会自动在地图缩放时隐藏和显示MKMarkerAnnotationView
s。
这会带来一个不幸的副作用,即可能导致.selectAnnotation()
无法可靠工作,因为标记在居中地图后仍然可能被隐藏。
我已经看过文档并理解其中的原因:
如果指定的注释未在屏幕上,并且因此没有关联的注释视图,则此方法无效。
有没有办法禁用注释聚合/隐藏?或者有没有一种方法来强制选择的注释可见?
selectAnnotation
。(我不知道showAnnotation方法是否会改变缩放级别;它可能会改变缩放级别)。 - aksh1t