调整大小后调整UIPopoverController位置 [英] Adjust UIPopoverController position after resize

查看:120
本文介绍了调整大小后调整UIPopoverController位置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含 UITableView UIPopoverController 。弹出窗口在其视图控制器的 -viewDidAppear 函数中调整大小,以适应表的内容。当popover正确调整时,它的箭头通常不再指向原来的 CGRect 。是否有办法强制popover在调整大小后重新定位自己,以使其箭头指向其预期目标?

I have a UIPopoverController containing a UITableView. The popover is resized in its view controller's -viewDidAppear function to fit the contents of the table. While the popover resizes properly, its arrow is usually no longer pointing at the original CGRect. Is there a way to force the popover to reposition itself after a resize so that its arrow is pointing at its intended target?

编辑:无法在 -viewDidLoad 中设置弹出框的大小,因为表视图不会加载其数据,直到 -viewDidAppear 被调用,因此我不知道popover应该是什么大小。此外,当一个表视图单元格被点击显示另一个视图时,我调整弹出框的大小,这也导致箭头不再指向其预期目标。

I can't set the size of the popover in -viewDidLoad since the table view does not load its data until -viewDidAppear is called, and as a result I do not know what size the popover should be until then. In addition, I resize the popover when one of the table view cells is clicked to display another view and this also results in the arrow no longer pointing at its intended target.

推荐答案

我认为这可能是错误的方式去做,因为你必须重新做内置的行为,定位箭头开始。

I think this may be the wrong way to go about it, since you're having to re-do the built-in behaviour that positions the arrow to begin with.

我不调整 viewDidAppear 中的popover内容。我在视图控制器的 viewDidLoad 方法中设置 contentSizeForViewInPopover 属性,例如:

I don't resize popover content in viewDidAppear. I set the contentSizeForViewInPopover property in the view controller's viewDidLoad method, e.g.:

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.contentSizeForViewInPopover = CGSizeMake(320, 155); // sized for a 3-row UITableView
}

(快速警告:重新开发通用应用程序,此代码将导致运行3.1.x及以下版本的设备的运行时崩溃。)

(Quick warning: if you're developing a universal app, this code will cause a run-time crash on devices running 3.1.x and below.)

您还可以设置弹出框的内容大小控制器之前,你应该照顾你的问题。查看 popoverContentSize 属性。

You can also set the content size for the popover controller before you present it, which should take care of your problem. Check out the popoverContentSize property.

这篇关于调整大小后调整UIPopoverController位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆