ios 如何将 UIPopoverView 显示为地图视图的注释?(iPad)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/5582564/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I display a UIPopoverView as a annotation to the map view? (iPad)
提问by Robert
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.
在 iPad 中的地图应用程序上,当你点击一个大头针时,你会得到一个带有“i”而不是显示指示器的普通注释。进一步点击“i”会显示一个像这样的弹出视图控制器。
Is there a way to easily achieve this?
有没有办法轻松实现这一目标?
回答by
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).
首先向地图添加注释,然后在viewForAnnotation
方法中,将 设置rightCalloutAccessoryView
为类型的按钮,例如 UIButtonTypeDetailDisclosure(我认为默认情况下蓝色信息按钮不可用)。
Pressing the button will call the calloutAccessoryControlTapped
delegate method. In this method, deselect the annotation and show your popover. For example:
按下按钮将调用calloutAccessoryControlTapped
委托方法。在此方法中,取消选择注释并显示您的弹出框。例如:
- (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 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.
YourContentViewController 是 UIViewController 的子类,您可以像任何其他视图控制器一样对其进行编码。地图应用程序看起来像是在内容中包含 UITableView。
回答by Bejil
It appears that to have a better position for the popover you must present it from this rect:
似乎要为 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);
回答by nevan king
You can use a library like Gordon Hughes' Animated Callout. Unfortunately it's still not working perfectly on iOS 6 (callouts show up strangely).
您可以使用 Gordon Hughes 的Animated Callout 之类的库。不幸的是,它仍然不能在 iOS 6 上完美运行(标注显示很奇怪)。
Here's iOS 5:
这是iOS 5:
回答by Ciprian Rarau
My requirement was similar to this issue, but also needed to allow users to interact with the map (panning and zooming) while the callout is displayed. For this I've created this github project: https://github.com/crarau/mapkit-custom-callout
我的要求与此问题类似,但还需要允许用户在显示标注时与地图进行交互(平移和缩放)。为此,我创建了这个 github 项目:https: //github.com/crarau/mapkit-custom-callout