如何将Button添加到userLocation标注? [英] How to add Button to userLocation callout?
问题描述
如何在Apple Maps应用程序的userLocation(蓝点)标注中显示DisclosureButton?
How can I display a DisclosureButton in the userLocation (the blue dot) callout like the Apple Maps app does?
现在我可以更改其标题和副标题,但我希望提供自定义标注视图。因此,如果我点击蓝点,它除了标题和副标题外还可以显示一个按钮。这样,当我点击按钮时,它可以引导我到另一个视图。
当注释== self.mapView.userLocation时,我在viewForAnnotation中返回了MKAnnotationView。但是,标注可以显示更新的标题和副标题,但不能显示我添加的按钮。
Now I just can change its title and subtitle, but I hope to provide custom callout views. Therefore, if I click the blue dot, it can display a button besides only title and subtitle. In this way, when I click the button, it can guide me to another View. I returned MKAnnotationView in viewForAnnotation when annotation == self.mapView.userLocation. However, the callout can display updated title and subtitle, but cannot show the button I added.
我真的需要这个功能,我希望得到任何帮助和建议!
I really need this function, and I desire any help and suggestion!
推荐答案
我已经尝试了 camdaochemgio 的解决方案,但它仅适用于第二次点击。这是一个永远有效的解决方案:
I've tried camdaochemgio's solution, but it works only for the second tap. Here is a solution which will always work:
-(void)mapView:(MKMapView *)mapView didAddAnnotationViews:(NSArray *)views
{
for (MKAnnotationView* view in views)
{
if ([view.annotation isKindOfClass:[MKUserLocation class]])
{
view.rightCalloutAccessoryView=[UIButton buttonWithType:UIButtonTypeDetailDisclosure];
}
}
}
这篇关于如何将Button添加到userLocation标注?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!