我有一個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