标题和副标题可以添加到iOS使用 MKUserLocation显示的用户位置.当用户点击该位置时,这些标题和副标题将显示在该位置上方的气泡中.通过使用setSelected:animated:from MKAnnotationView选择注释
如何以编程方式选择用户位置,以便注释显示在用户位置上而无需用户首先点击它?
MKAnnotationView的文档说明了它的setSelected:animated:方法(以及它所选属性的类似内容):You should not call this method directly.
相反,使用MKMapView方法selectAnnotation:animated:.如果在didAddAnnotationViews委托方法中调用它,则可以确保注释视图已准备好显示标注,否则调用selectAnnotation将不执行任何操作.
例如:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
for (MKAnnotationView *av in views)
{
if ([av.annotation isKindOfClass:[MKUserLocation class]])
{
[mapView selectAnnotation:av.annotation animated:NO];
//Setting animated to YES for the user location
//gives strange results so setting it to NO.
return;
}
}
}
