在 iPad 中将 uipopover 居中

发布于 2024-10-03 05:59:21 字数 348 浏览 7 评论 0原文

我想为 iPad 创建一个新键盘。

我设计了一个视图,其中包含按键和所有底层工作,以在用户按下按键时填充文本框,并在用户按下返回按钮时将值传递回调用例程。

这一切都正常。

现在 - 我想创建这个视图作为弹出窗口。

我已经完成了基本操作(弹出并被取消),

但现在我需要一些微调帮助。

这是我的问题...

1)如何在没有 UIPopoverArrowDirectionAny 选择的情况下创建以屏幕为中心的弹出窗口?

2)确保弹出窗口的大小是我在 XIB 文件中创建的大小(目前,它调整大小并删除窗口最右边的一些大小)

谢谢
托尼

I would like to create a new keyboard for the iPad.

I have designed a view that has the keys and all the underlying work to fill in a textbox as the user presses the keys, and passes the value back to the calling routine when the user presses the return button.

This all works ok.

Now - I want to create this view as a popover.

I have the basic operations complete (pops up and is dismissed)

But now I need some fine tuning help.

Here are my questions...

1) How do I create a popover window centered on the screen without a UIPopoverArrowDirectionAny selection?

2) Ensure the popover window is the size that I created it with in the XIB file (currently, it resizes and removes some of the rightmost size of the window)

Thanks
tony

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

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

发布评论

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

评论(3

天邊彩虹 2024-10-10 05:59:21

要在没有箭头的情况下显示它,请为“permissedArrowDirections”传递 0:

[popOverController presentPopoverFromRect:rect inView:view permittedArrowDirections:0 animated:YES];

要使其居中,请传递位于视图中心的 1x1 矩形:

CGRect rect = CGRectMake(viewWidth/2, viewHeight/2, 1, 1);
[popOverController presentPopoverFromRect:rect inView:view permittedArrowDirections:0 animated:YES];

然后您将获得一个居中且无箭头的弹出框。

移除箭头的部分随时可能断裂。他们没有提供 UIPopoverArrowDirectionNone 选项是有原因的,他们可能会选择在将来传递 0 时抛出异常,或者默认为某个值。使用它的风险由您自行承担。

To present it with no arrows pass 0 for "permittedArrowDirections":

[popOverController presentPopoverFromRect:rect inView:view permittedArrowDirections:0 animated:YES];

To center it, pass a 1x1 rect located at the center of your view:

CGRect rect = CGRectMake(viewWidth/2, viewHeight/2, 1, 1);
[popOverController presentPopoverFromRect:rect inView:view permittedArrowDirections:0 animated:YES];

Then you have a centered and arrow-free popover.

The bit about removing the arrow could break at any time. They didn't provide a UIPopoverArrowDirectionNone option for a reason, they may choose to throw an exception in the future when 0 is passed, or default to something. Use it at your own risk.

罪歌 2024-10-10 05:59:21

如果您使用的是 UIPopoverController,它将有一个箭头。这是您的选择。

UIPopoverArrowDirectionAny  
UIPopoverArrowDirectionUp
UIPopoverArrowDirectionDown
UIPopoverArrowDirectionLeft
UIPopoverArrowDirectionRight

正如您所看到的,没有 UIPopoverArrowDirectionNone

至于 XIB 大小,在您的实现文件的 ViewDidLoad 方法中,您可以设置以下内容。

self.contentSizeForViewInPopover = CGSizeMake(320.0, 360.0);

您可以按照自己喜欢的方式设置弹出窗口的大小。

If you are using a UIPopoverController, it will have an arrow. Here are your choices.

UIPopoverArrowDirectionAny  
UIPopoverArrowDirectionUp
UIPopoverArrowDirectionDown
UIPopoverArrowDirectionLeft
UIPopoverArrowDirectionRight

As you can see there is no UIPopoverArrowDirectionNone

As for the XIB size, in your ViewDidLoad Method of the implementation file, you can set the following.

self.contentSizeForViewInPopover = CGSizeMake(320.0, 360.0);

You can set the size any way you like for the popover.

So要识趣 2024-10-10 05:59:21

我刚刚解决了这个问题,但想在故事板中做尽可能多的事情,这稍微改变了方法:

1)在故事板中选择弹出窗口,然后取消勾选方向向上/向下/向左/向右以摆脱的箭头。

要将其集中在屏幕覆盖上,请为segue做好准备并执行以下操作:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIStoryboardPopoverSegue* popover = (UIStoryboardPopoverSegue*)segue;
    CGFloat horizontalInset = (self.view.frame.size.width - popover.popoverController.popoverContentSize.width) / (CGFloat)2.0;
    CGFloat verticalInset = (self.view.frame.size.height - popover.popoverController.popoverContentSize.height) / (CGFloat)2.0;
    popover.popoverController.popoverLayoutMargins =
        UIEdgeInsetsMake(
            verticalInset,
          horizontalInset,
            verticalInset,
          horizontalInset);
}

在我的情况下,我还发现弹出框segue的角半径与我的设计不匹配,因此我将背景颜色更改为清除以进行排序,即将其添加到上面的块:

popover.popoverController.backgroundColor = [UIColor clearColor];

2)在segue的目标控制器中找到属性“Popover”并勾选“使用显式大小”并输入您希望它以弹出模式显示的大小。

I've just been working this one out but wanted to do as much in the storyboard as possible which changes the approach a bit:

1) Select the popover in the storyboard and un-tick Directions Up/Down/Left/Right to get rid of the arrows.

To center it on screen override prepare for segue and do something like this:

- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    UIStoryboardPopoverSegue* popover = (UIStoryboardPopoverSegue*)segue;
    CGFloat horizontalInset = (self.view.frame.size.width - popover.popoverController.popoverContentSize.width) / (CGFloat)2.0;
    CGFloat verticalInset = (self.view.frame.size.height - popover.popoverController.popoverContentSize.height) / (CGFloat)2.0;
    popover.popoverController.popoverLayoutMargins =
        UIEdgeInsetsMake(
            verticalInset,
          horizontalInset,
            verticalInset,
          horizontalInset);
}

In my case I also found that the popover segue's corner radius didn't match my design so I change the background color to clear to sort that out i.e. add this to the above block:

popover.popoverController.backgroundColor = [UIColor clearColor];

2) In the destination controller for the segue find the attribute 'Popover' and tick 'Use Explicit Size' and put the size of you want it to appear in popover mode.

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