2010-09-07 124 views
11

我正在將一個註釋加載到我的地圖視圖上。加載地圖時,註釋顯示爲引腳。如何在地圖上自動顯示標題/副標題(pin)

但是,標題和副標題不會自動出現在引腳上。目前,用戶需要在標題顯示之前點擊該引腳。

有沒有辦法讓地圖加載時自動顯示標題?

(這個問題是幾乎同樣的事情,但也不能令人信服:To display the title for the current loaction in map in iphone,因爲我已經在我的對象中定義的-title和-subtitle屬性。)

感謝

回答

16

的方法調用是來自MKMapView的「selectAnnotation:animated」。

9
- (void)mapView:(MKMapView *)mv didAddAnnotationViews:(NSArray *)views 
{  
    MKAnnotationView *annotationView = [views objectAtIndex:0]; 
    id<MKAnnotation> mp = [annotationView annotation]; 
    MKCoordinateRegion region = MKCoordinateRegionMakeWithDistance([mp coordinate] ,350,350); 

    [mv setRegion:region animated:YES];  

    [mapView selectAnnotation:mp animated:YES]; 

} 

如果你正在做這是調用setRegion方法同樣的事情,然後確保你叫

[mapView selectAnnotation:mp animated:YES]; 

[mv setRegion:region animated:YES];  
0

在iOS的11起,有一個新的MKAnnotationView調用MKMarkerAnnotationView,它可以顯示標題和副標題而不被選中。檢查https://developer.apple.com/documentation/mapkit/mkmarkerannotationview

func mapView(_ mapView: MKMapView, viewFor annotation: MKAnnotation) -> MKAnnotationView? { 

    guard !(annotation is MKUserLocation) else { 
     return nil 
    } 

    if #available(iOS 11.0, *) { 
     let annoView = MKMarkerAnnotationView(annotation: annotation, reuseIdentifier: "HunterAnno") 
     annoView.canShowCallout = true 
     return annoView 
    } 

    let annoView = MKPinAnnotationView(annotation: annotation, reuseIdentifier: "HunterAnnoLow") 
    annoView.canShowCallout = true 
    return annoView 
} 
+1

雖然此鏈接可以回答這個問題,最好是在這裏有答案的主要部件,並提供鏈接以供參考。如果鏈接頁面更改,則僅鏈接答案可能會失效。 - [來自評論](/ review/low-quality-posts/17880863) – stdunbar 2017-11-08 17:53:25

相關問題