如何显示UIPopoverView作为地图视图的注释? 总览

在iPad中的地图应用程序中,当你点击一个别针,你会得到一个正常的注释与“我”而不是披露指标。 进一步点击“我”显示一个像这样的popover视图控制器。

地图弹窗示例

有没有办法轻松实现这一点?

首先在地图和viewForAnnotation方法中添加一个注释,将rightCalloutAccessoryView设置为一个types的button,比如UIButtonTypeDetailDisclosure(我不认为蓝色信息button默认可用)。

按下button将调用calloutAccessoryControlTapped委托方法。 在这种方法中,取消select注释并显示popup窗口。 例如:

 - (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。

看起来,要有一个更好的位置为popover您必须从这rect提出它:

 CGPoint lc_point = [mapView convertCoordinate:view.annotation.coordinate toPointToView:mapView]; CGRect lc_frame = CGRectMake(lc_point.x,lc_point.y-view.frame.size.height,0,0); 

您可以使用像Gordon Hughes的Animated Callout这样的图书馆。 不幸的是,它仍然不能完美的在iOS 6上(标注出现奇怪)。

这里是iOS 5:

在这里输入图像描述

我的要求与此问题相似,但也需要允许用户在显示标注时与地图进行交互(平移和缩放)。 为此我创build了这个github项目: https : //github.com/crarau/mapkit-custom-callout