2011-04-07 77 views

回答

58

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

按下按钮将调用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是的UIViewController的一个子类,其可以编码像任何其他视图控制器。地图应用看起来像在内容中具有UITableView。

+0

很好的答案,真的很详细。 – Robert 2011-04-07 16:37:06

+0

在地图应用程序中,在这种情况下有一个有趣的动画,而不是较小的气泡被解散和新的弹出窗口,小气泡实际上扩展到适合弹出视图。任何想法如何做到这一点? – 2011-08-17 17:39:23

+0

@Chris Wagner:不知道Maps应用是如何执行它,但是尝试最初显示具有较小高度的弹出窗口,然后使用timer或performSelector:withObject:afterDelay,手动激活popoverContentSize并使用更新的rect重新呈现弹出窗口(原点向上移动,身高增加)。另一个选择可能是首先显示/动画从中间展开的常规自定义UIView,然后显示最终大小的弹窗(并移除下面的自定义UIView)。在地图应用程序中,标注也左右移动,这可以通过更新view.calloutOffset来完成。 – Anna 2011-08-17 19:09:27

2

看来,有对酥料饼的一个更好的位置,你必须从该矩形目前它:

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); 
2

您可以使用像戈登休斯Animated Callout库。不幸的是,它仍然不能在iOS 6上完美运行(标注出现奇怪)。

这里的iOS 5:

enter image description here

相关问题