启动屏幕XIB:缺少宽度/高度限制(Xcode 6) [英] Launch Screen XIB: Missing Width / Height Constraints (Xcode 6)
问题描述
使用 Xcode 6 ,我正在构建针对 iOS8 的iOS应用.
Using Xcode 6, I am building an iOS app that targets iOS8.
我正在处理LaunchScreen.xib
文件,该文件是通过菜单File > New > File > iOS - User Interface - Launch Screen
创建的.启用使用自动布局".
I'm working on a LaunchScreen.xib
file, created from the menu: File > New > File > iOS - User Interface - Launch Screen
. "Use Auto Layout" is enabled.
在XIB的主UIView
内,我放置了UIImageView
.我想添加宽度和高度约束,以使UIImageView
与容器具有相同的大小.但是,Xcode不允许我这样做:我只能使用间距和对齐方式.
Inside the XIB's main UIView
, I've placed a UIImageView
. I would like to add width and height constraints, so that the UIImageView
has the same size as the container. However, Xcode doesn't let me do that: I can only work with spacing and alignment.
这是我看到的:
我做错了什么?为什么看不到以下菜单?
What am I doing wrong? Why can't I see a menu like the following?
我知道可以通过将容器的前导空间,尾随空间,顶部空间和底部空间设置为0来达到相同的结果,但是我也想了解这里发生的事情.
I know I could reach the same result by setting leading space, trailing space, top space, and bottom space to container to 0, but I would also like to understand what's happening here.
推荐答案
Xcode 7 + 默认为启动屏幕的情节提要文件.
如下所述,与XIB不同,情节提要文件允许您将宽度和高度约束设置为根UIView
.
Xcode 7+ defaults to a Storyboard file for the Launch Screen.
As explained below, unlike XIBs, Storyboard files allow you to set width and height constraints to the root UIView
.
对于XIB为何如此表现,我还没有找到官方的解释,当根上有UIView
时.
在我看来,很奇怪的是,我们提供的默认设置(LaunchScreen.xib
)的行为与我们习惯的情节提要完全不同.
I haven't been able to find an official explanation as to why XIBs behave like that, when they have a UIView
at the root.
What looks weird to me is that what we are provided with as a default (LaunchScreen.xib
) isn't set up to behave exactly like the Storyboards we've got used to.
我选择的第一个解决方案是使用情节提要板而不是XIB绘制启动屏幕:
The first solution I opted for was using a Storyboard to draw the Launch Screen, instead of a XIB:
- 删除
LaunchScreen.xib
- 创建
LaunchScreen.storyboard
(菜单:File > New > File > iOS - User Interface - Storyboard
) - 转到项目属性,选择导航至目标的常规属性,然后在启动屏幕文件"组合框中选择
LaunchScreen.storyboard
- 打开
LaunchScreen.storyboard
,添加一个View Controller,然后确保以勾选是初始View Controller框" - 您现在可以在视图控制器"的视图"上作为启动屏幕"使用,并且会得到我最初正在寻找的宽度和高度约束
- Delete
LaunchScreen.xib
- Create a
LaunchScreen.storyboard
(Menu:File > New > File > iOS - User Interface - Storyboard
) - Go to your project properties, select navigate to your target's general properties and select
LaunchScreen.storyboard
in the "Launch Screen File" combo box - Open
LaunchScreen.storyboard
, add a View Controller, and make sure to tick the "Is Initial View Controller Box" - You can now work on the View Controller's View as your Launch Screen, and you'll get the width and height constraints I was initially looking for
另一种解决方案是删除LaunchScreen.xib
中的默认UIView
,然后将其替换为View Controller.
与前面的情况一样,如果这样做,则可以在View Controller的View上进行操作,然后将获得通常的约束菜单.
An alternative solution is removing the default UIView
in LaunchScreen.xib
and replacing it with a View Controller.
Just like in the previous case, if you do so, you can work on the View Controller's View, and you'll get the usual constraint menu.
这篇关于启动屏幕XIB:缺少宽度/高度限制(Xcode 6)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!