【问题标题】:view frame does not move down 20px (height of the statusbar)视图框架不向下移动 20px(状态栏的高度)
【发布时间】:2015-02-16 17:24:04
【问题描述】:

我使用下面的代码来展示 vViewController1

  @property (retain,nonatomic) ViewController1 *vViewController1;

...

从 rootViewController 推送 vViewController1

  [self.navigationController pushViewController:vViewController1 animated:NO];

Viewcontroller1 的 viewWillAppear

- (void) viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];


    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
        CGRect screen = [[UIScreen mainScreen] bounds];
        if (self.navigationController) {
            CGRect frame = self.navigationController.view.frame;
            frame.origin.y = 20;
            frame.size.height = screen.size.height - 20;
            self.navigationController.view.frame = frame;

        } else {
            if ([self respondsToSelector: @selector(containerView)]) {
                UIView *containerView = (UIView *)[self performSelector: @selector(containerView)];

                CGRect frame = containerView.frame;
                frame.origin.y = 20;
                frame.size.height = screen.size.height - 20;
                containerView.frame = frame;
            } else {
                CGRect frame = self.view.frame;
               frame.origin.y = 20;
               frame.size.height = screen.size.height - 20;
                self.view.frame = frame;

            }
        }
    }  

}

但它显示如下,并没有向下移动 20px(状态栏的高度)

欢迎评论

【问题讨论】:

    标签: ios iphone ios7 ios8


    【解决方案1】:

    假设您没有使用 Autolayout(看到您正在使用帧大小)然后在 Storyboard 中选择 ViewController,然后转到 Size Inspector(小标尺),然后调整视图的 Y 增量(更改为 20 或 - 20 取决于您“查看为”的模式)。

    这可能对here 有所帮助,虽然我不确定 Y 中的 18 值,但我一直认为它是 20!

    【讨论】:

    • 我不使用 Storyboard,只是在没有自动布局的情况下查看,我的代码在 ios7 中工作但在 ios 8 中失败
    猜你喜欢
    • 1970-01-01
    • 2017-11-30
    • 2015-03-12
    • 2014-02-08
    • 2012-01-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多