UIPopoverController 内容视图大小

Posted

技术标签:

【中文标题】UIPopoverController 内容视图大小【英文标题】:UIPopoverController's content view size 【发布时间】:2011-06-21 23:21:13 【问题描述】:

我有一个 UIPopoverController,我从 iPad 上的 CGRect 呈现,如下所示:

MarkersPopViewController *markersPop = [[MarkersPopViewController alloc] initWithNibName:@"MarkersPopView" bundle:nil];
self.TestPopoverController = [[[UIPopoverController alloc] initWithContentViewController:markersPop] autorelease];
[TestPopoverController presentPopoverFromRect:CGRectMake(20, 20, 700, 500) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];

我的 MarkersPopView 是一个容器视图,它有一个 UITableView 占据了 .xib 的大部分,还有一个 UISegmentedControl 就在 UITableView 的顶部上方。 UITableView 使用 UITableViewCell 的自定义子类,其中每一行是 (700, 100)。

当我运行我的应用程序时,PopoverController 可能只有 50 磅宽并紧贴屏幕左侧。我想让视图的宽度适合初学者,然后居中。 UIPopoverController 这么小是有原因的吗?如果未使用 setPopoverContentSize: ,我认为 UIPopoverController 使用内容视图的默认大小。谢谢。

【问题讨论】:

【参考方案1】:

传递给 presentPopoverFromRect 的 CGRect 是弹出框将显示在某个的矩形。这不是弹出框将出现的框架

由于您要求箭头位于弹出框的右侧,因此它会尝试在 20,20,700,500 的左侧显示弹出框。

要在 20,20(实际上是箭头所在的位置)显示弹出框,请传递 20,20,1,1 的 CGRect。

您可能仍需要指定 popoverContentSize。

【讨论】:

以上是关于UIPopoverController 内容视图大小的主要内容,如果未能解决你的问题,请参考以下文章

UIPopoverController 以不同的速度调整弹出框和内容视图控制器(uinavigationcontroller)的大小

在 iPad 上的 UIPopoverController 中显示 iPhone-View (iPhone SDK)

UIPopoverController:关闭后更新视图

Xcode5 iOS7 - UIPopoverController 角半径

在 UIPopoverController 中将 contentView 居中

调整大小后调整 UIPopoverController 位置