我需要在所有其他註釋之上繪製當前用戶註釋(藍點)。現在它在我的其他註釋下被繪製並隱藏起來。我想調整這個註解視圖的Z-index(藍點)並將它帶到最高點,有誰知道如何?iOS MapKit用戶位置註釋的Z索引
更新: 所以我現在可以得到一個MKUserLocationView的句柄,但我該如何把它轉發?
- (void) mapView:(MKMapView *)aMapView didAddAnnotationViews:(NSArray *)views {
for (MKAnnotationView *view in views) {
if ([[view annotation] isKindOfClass:[MKUserLocation class]]) {
// How do I bring this view to the front of all other annotations?
// [???? bringSubviewToFront:????];
}
}
}
這個解決方案對我來說似乎並不可靠。如果我拖動地圖使其偏離屏幕並返回到地圖,藍色地點點就會在我的自定義註釋下面結束,大概是因爲地圖視圖會用原始佈局重新繪製視圖。 –
@DanJ然後使用' - (void)mapView:(MKMapView *)mapView regionWillChangeAnimated:(BOOL)animated'中的相同邏輯並通過mapView.annotations循環並找到'[mapView viewForAnnotation:annotation]' – jmcopeland
好點,解決問題,儘管我發現將regionDidChangeAnimated中的代碼放在比regionWillChangeAnimated更可靠的代碼中。我會更新您的答案以包含額外的代碼。 FTR,當使用大量註釋時,會有輕微的性能問題,因爲ChangeAnimated方法應儘可能輕量化。 –