UIPopoverController 的令人困惑的行为

发布于 2024-11-26 05:01:42 字数 749 浏览 0 评论 0原文

我试图设置一个弹出窗口,当我按下按钮时显示 UIDatePicker,但是我遇到了一些非常令人困惑的行为。我创建了一个视图控制器,其中只包含 UIDatePicker,将其连接到我需要它的类中,并将其添加到新的 UIPopoverController 中,如下所示:

self.timePickerPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.timePickerViewController];

然后我像这样呈现它:

[timePickerPopoverController presentPopoverFromRect:prepTimeButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

(prepTimeButton 是按下的按钮)。但是,我只是得到以下结果:

Broken UIPopoverController

而不是显示在按下的按钮旁边和目标处大小(现在太高了;应该只是日期选择器的大小)。我还尝试为其提供一个自定义视图,以显示要显示的正确位置和大小,但这并没有多大帮助(只是将弹出窗口移到屏幕的右半部分)。我做错了什么以及如何解决它?

I'm trying to set up a popover to appear that displays a UIDatePicker when I press a button, however I'm getting some very confusing behavior. I created a view controller that housed nothing but the UIDatePicker, wired one up in the class i needed it in, and added it to a new UIPopoverController like this:

self.timePickerPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.timePickerViewController];

then I present it like so:

[timePickerPopoverController presentPopoverFromRect:prepTimeButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

(prepTimeButton being the button that was pressed). However, I just get the following result:

Broken UIPopoverController

Instead of it displaying next to the button that was pressed and at the target size (it's way too tall right now; should only be the size of the date picker). I also tried giving it a custom view of the proper location and size in which to display, but that didn't help much (just shifted the popover to the right half of the screen). What am I doing wrong and how do I fix it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一抹淡然 2024-12-03 05:01:42

self.view 是 prepTimeButton 的直接超级视图吗?也许 prepTimeButton 嵌套在子视图中,在这种情况下,您需要将其用作 inView: 参数(或转换坐标)。

您是否设置了视图控制器的 contentSizeForViewInPopover 属性?

Is self.view the direct superview of prepTimeButton? Perhaps prepTimeButton is nested in a subview, in that case you'd need to use that as the inView: parameter (or convert the coordinates).

Did you set the contentSizeForViewInPopover property of your view controller?

日久见人心 2024-12-03 05:01:42

确保在内部视图控制器上设置 contentSizeForViewInPopover 并在 UIPopoverController 本身上设置 popoverContentSize

Make sure to set both contentSizeForViewInPopover on the internal view controller and popoverContentSize on the UIPopoverController itself.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文