我有一个TableView,用于在单击细胞时显示MapView注释标注。
在iOS中10 I可以集中在一个注解的MapView然后显示它使用的标注:显示群集时的MKAnnotation标注
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
s,在iOS 11上使用MKMarkerAnnotationView
s。
iOS 11在缩放地图时自动隐藏并显示MKMarkerAnnotationView。
这具有防止.selectAnnotation()
从工作可靠,因为标记仍然为中心的地图后,被隐藏的不幸的副作用。
我见过的文档和理解为什么:
如果指定的注释是不是屏幕上,因此不 有关联的标注视图,这种方法没有任何效果。
有没有办法可以禁用注释集群/隐藏? 或者某种方式强制选定的注释可见?
这不是一个解决方案,但可能是一种解决方法的想法:尝试以编程方式将地图缩放到更加放大的状态(您可以在缩放因子附近使用以获得它,以便注释不会重叠)后你以地图为中心。 – aksh1t
嗨@ aksh1t我考虑过这个,但我不想惹恼用户选择的缩放级别。另外,我的一些注释可以非常接近,所以这在某些情况下可能不起作用。 – Turnip
这很有道理。下面是我在查看其他一些mapview方法时得到的另一个想法:尝试用您的注释调用[showAnnotations:](https://developer.apple.com/documentation/mapkit/mkmapview/1452309-showannotations)方法,以及然后执行'selectAnnotation'。 (我不知道showAnnotation方法是否更改缩放级别;它可能确实会改变缩放级别)。 – aksh1t