如何以编程方式选择 MKUserLocation?
可以使用 MKUserLocation。当用户点击该位置时,这些将显示在该位置上方的气泡中。可以通过使用 setSelected:animated:
从 MKAnnotationView 选择注释来显示其他注释的思想气泡。不幸的是,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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MKAnnotationView
的文档介绍了其setSelected:animated:
方法(以及其selected
属性的类似内容):相反,请使用
MKMapView
方法selectAnnotation:animated:
。如果您在didAddAnnotationViews
委托方法中调用它,则可以确保注释视图已准备好显示标注,否则调用selectAnnotation
将不会执行任何操作。例如:
The documentation for
MKAnnotationView
says this about itssetSelected:animated:
method (and something similar for itsselected
property):Instead, use the
MKMapView
methodselectAnnotation:animated:
. If you call it in thedidAddAnnotationViews
delegate method, you can be sure the annotation view is ready to show the callout otherwise callingselectAnnotation
will do nothing.For example: