如何将 UIPopoverView 显示为地图视图的注释?(iPad) [英] 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 显示为地图视图的注释?(iPad)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!