如何将UIPopoverView显示为地图视图的注释?总览 [英] How do I display a UIPopoverView as a annotation to the map view? (iPad)
问题描述
点击图钉时,在iPad上的地图应用中,您会获得带有i而不是披露指示符的正常注释。进一步点击i会显示一个像这样的弹出视图控制器。
On the maps app in the IPad when you tap a pin you get a normal annotation with an "i" instead of a disclosure indicator. A further tap on the "i" reveals a popover view controller like this.
有没有办法轻松实现这个目标?
Is there a way to easily achieve this?
推荐答案
首先在地图上添加注释,在 viewForAnnotation
方法中,设置 rightCalloutAccessoryView
比较类型的按钮,比方说,UIButtonTypeDetailDisclosure(我认为默认情况下蓝色信息按钮不可用)。
First add an annotation to the map and in the viewForAnnotation
method, set the rightCalloutAccessoryView
to a button of type, say, UIButtonTypeDetailDisclosure (I don't think the blue info button is available by default).
按下按钮将调用 calloutAccessoryControlTapped
委托方法。在此方法中,取消选择注释并显示弹出窗口。例如:
Pressing the button will call the calloutAccessoryControlTapped
delegate method. In this method, deselect the annotation and show your popover. For example:
- (void)mapView:(MKMapView *)mapView annotationView:(MKAnnotationView *)view calloutAccessoryControlTapped:(UIControl *)control
{
[mapView deselectAnnotation:view.annotation animated:YES];
YourContentViewController *ycvc = [[YourContentViewController alloc] init...
UIPopoverController *poc = [[UIPopoverController alloc] initWithContentViewController:ycvc];
[ycvc release];
//hold ref to popover in an ivar
self.annotationPopoverController = poc;
//size as needed
poc.popoverContentSize = CGSizeMake(320, 400);
//show the popover next to the annotation view (pin)
[poc presentPopoverFromRect:view.bounds inView:view
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[poc release];
}
YourContentViewController是UIViewController的子类,您可以像任何其他视图控制器一样编码。地图应用程序看起来在内容中有UITableView。
YourContentViewController is a subclass of UIViewController which you can code like any other view controller. The Maps app looks like it has UITableView in the content.
这篇关于如何将UIPopoverView显示为地图视图的注释?总览的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!