简体   繁体   English

iOS模拟器无法在Xcode 6中正确显示

[英]iOS Simulator not displaying correctly in Xcode 6

I've been having such a hard time trying to figure out how this thing works. 我一直很难理解这个东西是如何工作的。 It's so random and I have no idea what else to try. 它是如此随机,我不知道还要尝试什么。 I've looked up multiple articles on this issue and everyone just says change the scale. 我看过有关此问题的多篇文章,每个人都说改变规模。 Changed the scale does not help, it's got nothing to do with what's happening here. 更改比例无济于事,它与这里发生的事情无关。 I'm not sure if this is related to the bottom of Xcode where you can change the dimensions (Any vs Any / Any vs Regular Height, etc...) I've asked my mobile development teacher at school as well and he couldn't figure it out either. 我不确定这是否与Xcode的底部有关,在这里您可以更改尺寸(任何vs任何/任何vs常规高度等)。我也问过我的移动开发老师在学校,他不能也不知道。 Any help would be greatly appreciated!! 任何帮助将不胜感激!!

Picture below: 下图:

http://tinypic.com/r/281fw5w/8 http://tinypic.com/r/281fw5w/8

Your problem is not scaling. 您的问题不是扩展。 What you need to look at is auto layout and constraints. 您需要查看的是自动布局和约束。

You can use the icons in the lower right edge of the interface builder to get at them or control drag from a view controller (like a button, label, etc.) to the containing view (or any other view controller for that matter.) Usually, the main view window itself. 您可以使用界面生成器右下角的图标来获取它们,或控制从视图控制器(如按钮,标签等)到包含视图(或与此相关的任何其他视图控制器)的拖动。通常,主视图窗口本身。 When you release you can now add constraints to "attach" the element to that other element relatively. 释放时,您现在可以添加约束以将元素相对“附加”到另一个元素。 For instance, you could attach the things on the left to the left side and the things on the right to the right side. 例如,您可以将左侧的东西连接到左侧,将右侧的东西连接到右侧。 Now, regardless of the dimension of the actual device screen, those elements will appear in those locations relative to the device screen. 现在,无论实际设备屏幕的尺寸如何,这些元素都将出现在相对于设备屏幕的那些位置。

The problem is that the position of elements from your perspective is right for the canvas you see in the Interface builder, but once the app is run, the real canvas has different dimensions. 问题在于,从您的角度看,元素的位置正好适合您在“界面”构建器中看到的画布,但是一旦运行应用程序,实际的画布就会具有不同的尺寸。

To manage the position, size and other attributes of UI elements, there is a system called AutoLayout. 为了管理UI元素的位置,大小和其他属性,有一个名为AutoLayout的系统 It is quite ingenious because it is similar to natural language. 它很巧妙,因为它类似于自然语言。 For example "I want this element to be in the middle of the screen." 例如,“我希望此元素位于屏幕中间。” or "I want this element to be 20 pixels from the left corner and 57 pixels from the element that is above this element." 或“我希望此元素距离左角20像素,距离此元素上方的元素57像素。”

By combining these rules you basically create a set of layout constraints, that are applied in runtime to the view hierarchy and view are laid out properly. 通过组合这些规则,您基本上可以创建一组布局约束,这些约束在运行时应用于视图层次结构,并且视图的布局正确。 Autolayout allows for very sophisticated layouts. 自动布局允许非常复杂的布局。

Another aspect you need to take into account that you might want your app to look well in all form factors from 3.5 inch iPhone up to iPad air. 您还需要考虑到另一方面,您可能希望您的应用在从3.5英寸iPhone到iPad air的所有外形上都看起来不错。 Since these devices differ considerably in size, Apple introduced an abstraction called Size Class . 由于这些设备的大小差异很大,因此Apple引入了一个称为Size Class的抽象。

Size Class is an abstraction on top of concrete size. 大小类是具体大小之上的抽象。 Concrete iOS devices have vey concrete dimensions. 具体的iOS设备具有具体的尺寸。 But in natural language you often say it's big ,or small ,or normal. 但是用自然语言,您经常会说它是大,小,还是正常。 And this the level of abstraction size classes use. 这是抽象大小级别使用的级别。

For each size class you can have a particular set of auto layout constraints. 对于每个尺寸类别,您可以具有一组特定的自动布局约束。

So by combining AutoLayout and SizeClasses , Apple solved the problem oh how to have one application but one that can still accommodate specific form factors and can adjust its layout to them. 因此,通过结合使用AutoLayout和SizeClasses ,Apple解决了以下问题:如何拥有一个应用程序,但仍然可以容纳特定形状并可以根据其调整布局的应用程序。

In Xcode6, all storyboards/xib files have autolayout & sizeclasses enabled by default. 在Xcode6中,所有情节提要/ xib文件默认情况下都启用了自动布局和大小类。 Interface builder provides you with a comfortable environment where you can set up your layout by creating constraints for each size class combination. 界面构建器为您提供了一个舒适的环境,您可以在其中通过为每种尺寸类别组合创建约束来设置布局。

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

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