ios Xcode 6 Storyboard 尺寸错误?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24105357/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Xcode 6 Storyboard the wrong size?
提问by Candyfloss
Built a new project from scratch in Swift in Xcode 6 (Beta 1) and have seen some strange behaviour with Storyboards and the output that I am viewing.
在 Xcode 6(Beta 1)中的 Swift 中从头开始构建一个新项目,并且在 Storyboards 和我正在查看的输出中看到了一些奇怪的行为。
I have built a simple interface (as shown below) - with properties of View Controller included. When I run this in the simulator I would expect 'Hello, World' to be central in the user interface - however it seems that this 'Square' is simply being fit into the iPhone screen and thus the wrong view is being shown (see below).
我构建了一个简单的界面(如下所示) - 包含视图控制器的属性。当我在模拟器中运行它时,我希望“Hello, World”成为用户界面的中心——然而,这个“Square”似乎只是适合 iPhone 屏幕,因此显示了错误的视图(见下文) )。
My question is: has anyone else seen this behaviour and how did they fix it?
我的问题是:有没有其他人看到过这种行为,他们是如何解决的?
Thanks!
谢谢!
采纳答案by Can Poyrazo?lu
While Asif Bilal's answer is a simpler solution that doesn't involve Size Classes (which were introduced in iOS 8.) it is strongly recommended you to get used to size classes as they are the future, and you will eventually jump in anyway at some point."
虽然 Asif Bilal 的答案是一个更简单的解决方案,它不涉及 Size Classes(在 iOS 8 中引入)。强烈建议您习惯 size classes,因为它们是未来,并且您最终会在某些时候加入观点。”
You probably haven't added the layout constraints.
您可能还没有添加布局约束。
Select your label, tap the layout constraints button on the bottom:
选择您的标签,点击底部的布局约束按钮:
On that menu add width and height (it should NOT be the same as mine) by checking their checkbox and click add constraints. Then Control-drag your label to your main view, and then when you de-click, you should have the options to center horizontally and vertically in container. Add both, and you should be set up.
在该菜单上,通过选中复选框并单击添加约束来添加宽度和高度(它不应与我的相同)。然后按住 Control 键将标签拖动到主视图,然后当您取消单击时,您应该可以选择在容器中水平和垂直居中。两者相加,你就应该设置好了。
回答by Asif Bilal
Do the following steps to resolve the issue
执行以下步骤来解决问题
In Storyboard, select any view, then go to the File inspector. Uncheck the "Use Size Classes", you will ask to keep size class data for: iPhone/iPad. And then Click the "Disable Size Classes" button. Doing this will make the storyboard's view size with selected device.
在 Storyboard 中,选择任何视图,然后转到文件检查器。取消选中“使用尺寸等级”,您将要求保留以下尺寸等级数据:iPhone/iPad。然后单击“禁用大小类”按钮。这样做将使故事板的视图大小与选定的设备。
回答by Eli Burke
If you are using Xcode 6 and designing for iOS 8, none of these solutions are correct. To get your iPhone-only views to be sized correctly, don't turn off size classes, don't turn off inferred metrics, and don't set constraints (yet). Instead, use the size class control, which is an easy to miss text button at the bottom of Interface Builder that initially reads "wAny hAny".
如果您使用的是 Xcode 6 并针对 iOS 8 进行设计,那么这些解决方案都不是正确的。为了让您的 iPhone 专用视图正确调整大小,不要关闭大小类,不要关闭推断指标,也不要设置约束(暂时)。相反,请使用大小类控件,它是 Interface Builder 底部的一个容易错过的文本按钮,最初显示为“wAny hAny”。
Click the button, and choose Compact Width, Regular Height. This resize your views and cover all iPhone portrait orientations. Apple's docs here: https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/SelectingASizeClass.htmlor search on "Selecting a Size Class in Interface Builder"
单击按钮,然后选择紧凑宽度、常规高度。这会调整您的视图大小并覆盖所有 iPhone 纵向。Apple 的文档在这里:https: //developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/SelectingASizeClass.html或搜索“在界面生成器中选择大小类”
回答by David Andrews
In Storyboard, select your ViewController and go to Atribute Inspector. At the very top, under Simulated Metrics you have Size and Orientation properties which are set to Inferred. Change them to desired values.
在 Storyboard 中,选择您的 ViewController 并转到 Atribute Inspector。在最顶部,在 Simulated Metrics 下,您具有设置为 Inferred 的 Size 和 Orientation 属性。将它们更改为所需的值。
In order for an application to display properly on another screen size, you also have to setup constraints, as described by Can Poyrazo?lu in the first post.
为了让应用程序在其他屏幕尺寸上正确显示,您还必须设置约束,如 Can Poyrazo?lu 在第一篇文章中所述。
回答by user2961953
I had this issue in xcode 6 and there is a way to resolve the resize conflicts. If you select your view, at the bottom you will see an icon that looks like |-Δ-|. If you click on it, you're project will resize for different devices.
我在 xcode 6 中遇到了这个问题,有一种方法可以解决调整大小冲突。如果您选择视图,您将在底部看到一个看起来像 |-Δ-| 的图标。如果单击它,您的项目将针对不同的设备调整大小。
回答by Priest
For anyone using XCode 7, it's very easy to design for a specific device size (instead of the default square-ish canvas).
对于使用 XCode 7 的任何人来说,设计特定设备尺寸(而不是默认的方形画布)非常容易。
In Interface Builder, select your ViewController or Scene from the left menu. Then under Show the Attributes Inspector
, go to the Simulated Metrics
, and pick the desired Size
from the dropdown menu.
在 Interface Builder 中,从左侧菜单中选择您的 ViewController 或 Scene。然后在 下Show the Attributes Inspector
,转到Simulated Metrics
,并Size
从下拉菜单中选择所需的。
回答by Rachel
Go to Attributes Inspector(right top corner) In the Simulated Metrics, which has Size, Orientation, Status Bar, Top Bar, Bottom Bar properties. For SIZE, change Inferred --> Freeform.
转到 Attributes Inspector(右上角)在 Simulated Metrics 中,它具有 Size、Orientation、Status Bar、Top Bar、Bottom Bar 属性。对于 SIZE,更改 Inferred --> Freeform。
回答by Ohmy
On your storyboard page, go to File Inspector and uncheck 'Use Size Classes'. This should shrink your view controller to regular IPhone size you were familiar with. Note that using 'size classes' will let you design your project across many devices. Once you uncheck this the Xcode will give you a warning dialogue as follows. This should be self-explainatory.
在故事板页面上,转到文件检查器并取消选中“使用大小类”。这应该将您的视图控制器缩小到您熟悉的常规 iPhone 大小。请注意,使用“大小类”可以让您在许多设备上设计您的项目。取消选中此项后,Xcode 将为您提供如下警告对话框。这应该是不言自明的。
"Disabling size classes will limit this document to storing data for a single device family. The data for the size class best representing the targeted device will be retained, and all other data will be removed. In addition, segues will be converted to their non-adaptive equivalents."
“禁用大小类将限制此文档存储单个设备系列的数据。最能代表目标设备的大小类数据将被保留,所有其他数据将被删除。此外,segue 将转换为非-自适应等价物。”
回答by swnn
You shall probably use the "Resolve Auto Layout Issues" (bottom right - triangle icon in the storyboard view) to add/reset to suggested constraints (Xcode 6.0.1).
您可能应该使用“解决自动布局问题”(右下角 - 故事板视图中的三角形图标)来添加/重置建议的约束(Xcode 6.0.1)。