简体   繁体   English

iOS 7状态和导航栏在故事板中的高度不同于应用程序

[英]iOS 7 status and navigation bar different height in storyboard than in app

This is a view controller than is modally presented and therefore full screen. 这是一个视图控制器,而不是模态显示,因此全屏。

In the storyboard, the "top layout guide" is at y:64 . 在故事板中,“顶部布局指南”位于y:64 That is what I would expect when the status bar is height:20 and navigation bar is height:44 . 当状态栏为height:20时,我会期待这一点height:20 ,导航栏height:44

However, when the app runs, the "top layout guide" is y:52 . 但是,当应用程序运行时,“顶部布局指南”为y:52 I have no idea how or why it's losing 12 points. 我不知道它是如何或为何失去12分。

When you use Apple's Navigation controller which inserts a navigation bar, it will have different heights based on your orientation. 当您使用Apple的导航控制器插入导航栏时,它将根据您的方向具有不同的高度。 For example, the navigation bar is 44 points in portrait and 32 points in landscape. 例如,导航栏为纵向44点,横向为32点。 In your case, I'm guessing when your app runs, it is in landscape, thus the "top layout guide" is y:52 (32+20). 在你的情况下,我猜你的应用程序何时运行,它是横向的,因此“顶部布局指南”是y:52(32 + 20)。

See this related post: NavigationBar with rotation. 请参阅此相关帖子: 带旋转的NavigationBar。

If you are trying to monitor these navigation bar height changes for example like this: 如果您尝试监视这些导航栏高度更改,例如:

-(void) viewDidLayoutSubviews
{
    [super viewDidLayoutSubviews];
    CGFloat navBarHeight = self.navigationController.navigationBar.frame.size.height;
}

You will realize that, although app changed orientation to landscape mode, navBarHeight 's value is still the old one ( 44 ). 你会意识到,虽然app将方向改为横向模式,但navBarHeight的价值仍然是旧的( 44 )。 To tackle this, use intrinsic size instead: 要解决这个问题,请使用内在大小:

-(void) viewDidLayoutSubviews
    {
        [super viewDidLayoutSubviews];
        CGFloat navBarHeight = self.navigationController.navigationBar.intrinsicContentSize.height;
    }

In general , you can't be sure that the geometries of objects in storyboard (or a nib) will be the final on-screen geometries. 通常 ,您无法确定故事板(或笔尖)中对象的几何形状是最终的屏幕几何形状。 The final on-screen geometries will depend upon not only device orientation, but also the screen dimensions (eg, 3.5-inch vs. 4-inch iPhone). 最终的屏幕几何形状不仅取决于设备方向,还取决于屏幕尺寸(例如,3.5英寸与4英寸iPhone)。

Unfortunately, it's easy to think otherwise. 不幸的是,否则很容易想到。 For example, if storyboard is simulating the 4-inch iPhone in portrait and you run the app in the 4-inch Simulator in portrait, then the final on-screen geometries will be the same as those in storyboard. 例如,如果故事板正在纵向模拟4英寸iPhone,并且您在4英寸模拟器中以纵向运行应用程序,那么最终的屏幕几何将与故事板中的几何相同。

To simulate different orientations or screen dimensions in storyboard, visit the view controller's Attributes inspector: 要在故事板中模拟不同的方向或屏幕尺寸,请访问视图控制器的“属性”检查器:

在此输入图像描述

If you're using Xcode 5, there's also a "floating" button on the IB canvas in the bottom-right-hand corner that allows you to quickly change which form factor is simulated. 如果你正在使用Xcode 5,那么在右下角的IB画布上还有一个“浮动”按钮,可以让你快速改变模拟的形状因子。

在此输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM