2010-09-07 127 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

相关问题