简体   繁体   English

Xcode 6 Storyboard大小错误?

[英]Xcode 6 Storyboard the wrong size?

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开始构建一个新项目,并且看到了Storyboard和我正在查看的输出的一些奇怪行为。

I have built a simple interface (as shown below) - with properties of View Controller included. 我已经构建了一个简单的界面(如下所示) - 包含View Controller的属性。 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! 谢谢!

从故事板编辑器中查看

属性检查员

大小检查员

模拟器输出

Do the following steps to resolve the issue 执行以下步骤以解决此问题

In Storyboard, select any view, then go to the File inspector. 在Storyboard中,选择任何视图,然后转到“文件”检查器。 Uncheck the "Use Size Classes", you will ask to keep size class data for: iPhone/iPad. 取消选中“使用大小类”,您将要求保留大小类数据:iPhone / iPad。 And then Click the "Disable Size Classes" button. 然后单击“禁用大小类”按钮。 Doing this will make the storyboard's view size with selected device. 这样做会使故事板的视图大小与所选设备一致。

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的答案是一个更简单的解决方案,它不涉及大小类(在iOS 8中引入),但强烈建议您习惯使用大小类,因为它们是未来,并且最终你会在某些方面跳入点。”


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. 然后按住Control键并将标签拖到主视图中,然后在单击时,应该选择在容器中水平和垂直居中。 Add both, and you should be set up. 添加两者,您应该进行设置。

If you are using Xcode 6 and designing for iOS 8, none of these solutions are correct. 如果您使用Xcode 6并为iOS 8设计,则这些解决方案都不正确。 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). 要使您的仅iPhone视图正确调整大小,请不要关闭大小类,不要关闭推断的指标,也不要设置约束(尚未)。 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". 相反,使用size类控件,它是Interface Builder底部的一个容易遗漏的文本按钮,最初读取“wAny hAny”。

Click the button, and choose Compact Width, Regular Height. 单击按钮,然后选择“紧凑宽度”,“常规高度”。 This resize your views and cover all iPhone portrait orientations. 这会调整视图大小并覆盖所有iPhone纵向方向。 Apple's docs here: https://developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/SelectingASizeClass.html or search on "Selecting a Size Class in Interface Builder" Apple的文档在这里: https//developer.apple.com/library/ios/recipes/xcode_help-IB_adaptive_sizes/chapters/SelectingASizeClass.html或搜索“在Interface Builder中选择大小类”

In Storyboard, select your ViewController and go to Atribute Inspector. 在Storyboard中,选择ViewController并转到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. 将它们更改为所需的值。

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. 为了使应用程序能够在另一个屏幕尺寸上正确显示,您还必须设置约束,如CanPoyrazoğlu在第一篇文章中所述。

I had this issue in xcode 6 and there is a way to resolve the resize conflicts. 我在xcode 6中遇到了这个问题,并且有一种方法可以解决调整大小冲突。 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. 如果单击它,您的项目将调整为不同的设备调整大小。

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. 对于SIZE,更改Inferred - > Freeform。

On your storyboard page, go to File Inspector and uncheck 'Use Size Classes'. 在Storyboard页面上,转到File Inspector并取消选中“Use Size Classes”。 This should shrink your view controller to regular IPhone size you were familiar with. 这应该将您的视图控制器缩小到您熟悉的常规IPhone大小。 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. 取消选中后,Xcode将为您提供如下警告对话框。 This should be self-explainatory. 这应该是自我解释的。

"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." “禁用大小类会将此文档限制为存储单个设备系列的数据。将保留最能代表目标设备的大小类的数据,并删除所有其他数据。此外,segues将转换为非 - 适应性等价物。“

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. 在Interface Builder中,从左侧菜单中选择ViewController或Scene。 Then under Show the Attributes Inspector , go to the Simulated Metrics , and pick the desired Size from the dropdown menu. 然后在Show the Attributes Inspector ,转到Simulated Metrics ,从下拉菜单中选择所需的Size

您可能会使用“解决自动布局问题”(右下角 - 故事板视图中的三角形图标)来添加/重置建议的约束(Xcode 6.0.1)。

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

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