UIPopoverController 的令人困惑的行为
我试图设置一个弹出窗口,当我按下按钮时显示 UIDatePicker,但是我遇到了一些非常令人困惑的行为。我创建了一个视图控制器,其中只包含 UIDatePicker,将其连接到我需要它的类中,并将其添加到新的 UIPopoverController 中,如下所示:
self.timePickerPopoverController = [[UIPopoverController alloc] initWithContentViewController:self.timePickerViewController];
然后我像这样呈现它:
[timePickerPopoverController presentPopoverFromRect:prepTimeButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
(prepTimeButton 是按下的按钮)。但是,我只是得到以下结果:
而不是显示在按下的按钮旁边和目标处大小(现在太高了;应该只是日期选择器的大小)。我还尝试为其提供一个自定义视图,以显示要显示的正确位置和大小,但这并没有多大帮助(只是将弹出窗口移到屏幕的右半部分)。我做错了什么以及如何解决它?
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:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
self.view 是 prepTimeButton 的直接超级视图吗?也许 prepTimeButton 嵌套在子视图中,在这种情况下,您需要将其用作 inView: 参数(或转换坐标)。
您是否设置了视图控制器的
contentSizeForViewInPopover
属性?Is
self.view
the direct superview ofprepTimeButton
? PerhapsprepTimeButton
is nested in a subview, in that case you'd need to use that as theinView:
parameter (or convert the coordinates).Did you set the
contentSizeForViewInPopover
property of your view controller?确保在内部视图控制器上设置
contentSizeForViewInPopover
并在UIPopoverController
本身上设置popoverContentSize
。Make sure to set both
contentSizeForViewInPopover
on the internal view controller andpopoverContentSize
on theUIPopoverController
itself.