【问题标题】:Shift frame inside UIPopoverControllerUIPopoverController 内的移动框架
【发布时间】:2013-08-21 15:06:49
【问题描述】:

我的通用应用程序在其设置屏幕中使用 NIB。我想为 iPhone 和 iPad 使用相同的 NIB。

因此,在 iPad 上,我在 MainViewController 中使用 UIPopoverController 进行设置,只需显示 iPhone 大小的 NIB,以显示所谓的 SettingsViewController。弹出框大小为 320x460 点。

这会导致一个问题,因为 iPhone 版本以编程方式在状态栏上方绘制了许多东西,而对于 iPad 版本,这不是必需的。 iPad 上的现状:

如您所见,“设置”标题上方有一个很大的空白区域。因此,我想要的是将视图控制器向上移动大约 20 个点,在弹出框内

弹出框在MainViewController中实例化如下:

        settingsPopoverController = [[UIPopoverController alloc] initWithContentViewController:popoverNavigationController];
        settingsPopoverController.popoverContentSize = CGSizeMake(320, 460);
        settingsPopoverController.delegate = self;
        popoverNavigationController.navigationBarHidden = YES;

在SettingsViewController中,我设置frame如下:

- (void)viewDidLoad
{
    self.contentSizeForViewInPopover = CGSizeMake(320, 460);
}

稍后在 SettingsViewController 中,我尝试按如下方式创建偏移量:

- (void)viewWillLayoutSubviews
{
    // shift it up
    CGRect frame = self.view.frame;
    frame.origin.y = -20;
    [self.view setFrame:frame];
}

这不会使内容稍微上移。怎么办?

澄清一下:我想向下移动弹出框显示的“视口”。

【问题讨论】:

    标签: ios ipad nib


    【解决方案1】:

    尝试:

    myPopover.autoresizingMask=UIViewAutoresizingNone;
    

    或者:

    myPopover.autoresizingMask=UIViewAutoresizingFlexibleHeight || UIViewAutoresizingFlexibleWidth;
    

    您也可以尝试将代码放入-(void)viewDidLayoutSubviews 方法中。 如果此答案没有帮助,请尝试设置 popoverLayoutMargins (property) 而不是 setFrame: 例如:

    popover.popoverLayoutMargins=UIEdgeInsetsMake (
    CGFloat 50, //top
    CGFloat 50,//left
    CGFloat 50,//bottom
    CGFloat 50//right
    );
    

    【讨论】:

    • UIPopoverController 没有 autoresizingMask 属性,不确定您的意思。将代码移动到 viewDidLayoutSubview 没有任何效果。
    • 在 IB 中尝试将 sligment 约束的优先级设置为最小值。
    • 您需要移动弹出框视图还是弹出框箭头?
    • 我在回答中又添加了一个解决方案。
    • 我需要移动弹出框的内容,而不是弹出框本身。我添加了一个额外的模型。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-02-03
    • 2011-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多