Xcode 布局在模拟器或真实设备中显示不正确

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11680464/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 01:02:37  来源:igfitidea点击:

Xcode Layout Not Appearing Right In Simulator or Real Device

iosxcodeios5layoutstoryboard

提问by Flatlyn

I have a layout working fine in Xcode storyboard for a Master-Detail splitview app but when I run it in the Simulator or on an actual device it appears slightly messed up and I have no idea why.

我有一个布局在 Xcode 故事板中为 Master-Detail splitview 应用程序工作正常,但是当我在模拟器或实际设备上运行它时,它看起来有点混乱,我不知道为什么。

The image in Xcode looks like this;

Xcode 中的图像如下所示;

Xcode Looking Fine

Xcode 看起来不错

The layout in Simulator and Device looks like this

Simulator 和 Device 中的布局如下所示

Messed up image

乱七八糟的图片

采纳答案by jonkroll

This is almost certainly a problem with the autoresizing settings of your subviews (aka "Springs and Struts").

这几乎肯定是子视图(又名“Springs and Struts”)的自动调整大小设置的问题。

You are building a UISplitViewController-based application. Note that the dimensions of your Detail View Controller's frame are different when your app is running in portrait vs landscape mode. In your storyboard screenshot above you see the landscape-sized frame. The screen capture from your simulator shows the portrait-size frame. You'll need to set the struts and springs of your subviews (the UIPickerView, the brushed metal buttons, the white box below, etc) so that these elements resize (or not) and maintain their relative (or absolute) position in the parent view.

您正在构建一个基于 UISplitViewController 的应用程序。请注意,当您的应用程序在纵向模式与横向模式下运行时,细节视图控制器框架的尺寸是不同的。在上面的故事板屏幕截图中,您会看到横向大小的框架。模拟器的屏幕截图显示了纵向尺寸的框架。您需要设置子视图的支柱和弹簧(UIPickerView、拉丝金属按钮、下面的白框等),以便这些元素调整大小(或不调整)并保持它们在父视图中的相对(或绝对)位置看法。

The easiest way to do this is to set the values in your storyboard, using the Size Inspector in the right column. Select which element you want to change settings for and then look for this:

最简单的方法是在故事板中设置值,使用右列中的大​​小检查器。选择要更改设置的元素,然后查找:

enter image description here

在此处输入图片说明

By clicking on the red arrows inside the inner box you will toggle on/off the "springs", which determine whether your subview expands when the parent view expands, or whether it maintains its original size when that happens. By clicking on the outer red I-bars you will toggle on/off the "struts", which determine whether you subview will maintain a fixed distance from its parent view's edge when the parent view's size changes. Setting the right combination of these will make your view to look correct in both portrait and landscape orientations.

通过单击内部框内的红色箭头,您将打开/关闭“弹簧”,这决定了您的子视图在父视图扩展时是否扩展,或者在发生这种情况时是否保持其原始大小。通过单击外部的红色 I-bars,您将打开/关闭“支柱”,它决定了当父视图的大小发生变化时,子视图是否与父视图的边缘保持固定距离。设置这些的正确组合将使您的视图在纵向和横向方向上看起来都正确。

You can also change these settings programmatically in your code by setting the view's autoresizingMaskproperty. See for reference:

您还可以通过设置视图的autoresizingMask属性在代码中以编程方式更改这些设置。见参考:

http://developer.apple.com/library/ios/DOCUMENTATION/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html#//apple_ref/doc/uid/TP40009503-CH5-SW5

http://developer.apple.com/library/ios/DOCUMENTATION/WindowsViews/Conceptual/ViewPG_iPhoneOS/CreatingViews/CreatingViews.html#//apple_ref/doc/uid/TP40009503-CH5-SW5