如何以编程方式选择MKUserLocation?

编程入门 行业动态 更新时间:2024-10-09 05:23:09
本文介绍了如何以编程方式选择MKUserLocation?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可以使用 MKUserLocation .当用户点击该位置时,这些内容将显示在该位置上方的气泡中.通过从MKAnnotationView中使用setSelected:animated:选择注释,可以显示其他注释的思想泡泡.不幸的是,MKUserLocation并非源自MKAnnotationView.

Titles and subtitles can be added to the user location that iOS shows using MKUserLocation. When the user taps on the location, these will show in a bubble above the location. The thought bubbles for other annotations can be shown by selecting the annotation with setSelected:animated: from MKAnnotationView. Unfortunately, MKUserLocation does not descend from MKAnnotationView.

如何以编程方式选择用户位置,以便注释显示在用户位置上方而无需用户先点击它?

How can I programmatically select the user location so the annotation appears over the user location without the user first tapping on it?

推荐答案

MKAnnotationView的文档说明了有关其setSelected:animated:方法(及其selected属性类似的内容)的信息:

The documentation for MKAnnotationView says this about its setSelected:animated: method (and something similar for its selected property):

您不应直接调用此方法.

You should not call this method directly.

而是使用MKMapView方法selectAnnotation:animated:.如果使用didAddAnnotationViews委托方法调用它,则可以确保注释视图已准备好显示标注,否则调用selectAnnotation将无济于事.

Instead, use the MKMapView method selectAnnotation:animated:. If you call it in the didAddAnnotationViews delegate method, you can be sure the annotation view is ready to show the callout otherwise calling selectAnnotation will do nothing.

例如:

-(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; } } }

更多推荐

如何以编程方式选择MKUserLocation?

本文发布于:2023-11-05 02:56:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1559716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:方式   MKUserLocation

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!