ios Xcode 5 布局错误 - 标签的错位视图框架在运行时会有所不同
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18739572/
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 5 layout errors - Misplaced View Frame for Label will be different at runtime
提问by Youssef Moawad
I just installed Xcode 5 and I am currently preparing my apps for release to the App Store on iOS 7 next week. I am getting a whole bunch of errors and warnings though.
我刚刚安装了 Xcode 5,我目前正在准备我的应用程序,以便下周在 iOS 7 上发布到 App Store。不过,我收到了一大堆错误和警告。
In one app where I have a UIPickerView, UITextFields and a bunch of UILabels. In this app it gives an Illegal Configuration
(red) error on almost all controls in the storyboard file. I don't know what that error is or how to fix it. I would appreciate some help on that. I can't completely recreate the file because there are 20 complicated views.
在一个应用程序中,我有一个 UIPickerView、UITextFields 和一堆 UILabels。在这个应用程序中,它Illegal Configuration
在故事板文件中的几乎所有控件上都会出现(红色)错误。我不知道那个错误是什么或如何修复它。我将不胜感激。我无法完全重新创建文件,因为有 20 个复杂的视图。
In another app there is a UIScrollView containing a bunch of UILabels and UITextFields, plus one UITextView that is created programmatically and contains text based on what you selected in a (previous view) UITableView as well as resizing itself to fit the content. The UIScrollView resizes to accommodate for the new size of the UITextView. This one compiles and builds and the UITextView gets created but doesn't contain the text, probably because it now resizes incorrectly. The UIScrollView now also scrolls horizontally in addition to vertically which it isn't supposed to. This one gives only (yellow) warnings which all say:
在另一个应用程序中,有一个 UIScrollView 包含一堆 UILabels 和 UITextFields,以及一个以编程方式创建的 UITextView,它包含基于您在(前一个视图) UITableView 中选择的内容以及调整自身大小以适应内容的文本。UIScrollView 调整大小以适应 UITextView 的新大小。这个编译和构建并创建了 UITextView 但不包含文本,可能是因为它现在不正确地调整大小。UIScrollView 现在除了垂直滚动之外还可以水平滚动,这是不应该的。这个只给出(黄色)警告,所有警告都说:
Misplaced View Frame for "Label - Symbol:" will be different at run time.
for 4 controls including this Label and another, a Text Field and the Scroll View.
Misplaced View Frame for "Label - Symbol:" will be different at run time.
对于 4 个控件,包括此标签和另一个,文本字段和滚动视图。
I would appreciate any help on this because this is the first time for me adjusting to a new version of Xcode and iOS.
我将不胜感激,因为这是我第一次适应新版本的 Xcode 和 iOS。
P.S: Details on the Illegal Configuration
error include:Auto Layout on iOS Versions prior to 6.0
PS:Illegal Configuration
错误的详细信息包括:Auto Layout on iOS Versions prior to 6.0
Thanks!
谢谢!
回答by Joel Fischer
If you're still looking for an answer here, the answer is likely that you have either no constraints, or improper constraints, on your AutoLayout view.
如果您仍在此处寻找答案,那么答案很可能是您的 AutoLayout 视图没有约束或不正确的约束。
You can fix this by selecting the view and going to the Xcode menu option: Editor -> Resolve Auto Layout Issues -> Add Missing Constraints / Reset to Suggested Constraints
.
您可以通过选择视图和去Xcode的菜单选项解决这个问题:Editor -> Resolve Auto Layout Issues -> Add Missing Constraints / Reset to Suggested Constraints
。
You can also select the entire layout and do the same thing, this will reset all of the views on your layout to recommended constraints.
您还可以选择整个布局并执行相同的操作,这会将布局上的所有视图重置为推荐的约束。
If you need to do custom constraints, you will have to set up your own auto layout constraints either in the Storyboard/XIB file, or manually in code.
如果需要自定义约束,则必须在 Storyboard/XIB 文件中或在代码中手动设置自己的自动布局约束。
For more information about Auto Layout, you can see Apple's documentation.
有关自动布局的更多信息,您可以查看Apple 的文档。
Finally, you can also turn off auto layout on the layout if you want it to appear as-is, with no automatic readjustments (this is not recommended).
最后,如果您希望布局按原样显示,没有自动重新调整(不推荐这样做),您还可以关闭布局上的自动布局。
回答by Morrowless
Reset to Suggested Constraints
sometimes does not get rid of this warning. The solution is to select Placeholder
in the Intrinsic Size
drop down menu in the Size inspector of the UIView in question. And then add the missing constraints as needed.
Reset to Suggested Constraints
有时并没有摆脱这个警告。解决方案是在相关 UIView 的大小检查器Placeholder
的Intrinsic Size
下拉菜单中进行选择。然后根据需要添加缺少的约束。
回答by ProgrammingNinja
Simply select your view controller Go to
只需选择您的视图控制器转到
Editor-->Resolve Autolayout issues--> Clear All Constraints in ViewController and you are done.
编辑器--> 解决自动布局问题--> 清除 ViewController 中的所有约束,您就完成了。
回答by memmons
Regarding Frame "Label frame will be different at run time" -- Please see the release notes under Autolayout: Runtime.
关于框架“标签框架在运行时会有所不同”——请参阅 Autolayout: Runtime 下的发行说明。
Full answer will be shown here after the NDA is lifted.
NDA 解除后,完整答案将在此处显示。
Note: this also happens under Xcode 4.2 as well, but the problem isn't surfaced by IB.
注意:这也发生在 Xcode 4.2 下,但 IB 没有发现问题。
回答by user2714257
Xcode now works with relative position against parent views. You can correct them to click on the orange lines and click on the mark and select use storyboard value or something
Xcode 现在使用相对于父视图的相对位置。您可以更正它们以单击橙色线条并单击标记并选择使用故事板值或其他内容
回答by Jay Versluis
Alternatively, you can switch off Auto Layout altogether.
或者,您可以完全关闭自动布局。
This approach comes in handy if you want to be compatible with iOS 5.
如果您想与 iOS 5 兼容,这种方法会派上用场。
回答by Nupur Sharma
I was also getting the same error in the two text fields I added in View controlller. What helped me to resolve the issue is: In the document Outline,I Ctr+draggedthe 1st text field up to the View and selected Center Horizontally in Container. Then I Ctr+draggedthe 2nd text field up to the View and selected Center Vertically in Container. Hope this helps you too.
我在视图控制器中添加的两个文本字段中也遇到了相同的错误。帮助我解决问题的是:在文档 Outline 中,我将第一个文本字段按Ctr+拖动到 View 并在 Container 中选择了Center Horizontally。然后我按Ctr+拖动第二个文本字段到 View 并选择Center Vertically in Container。希望这对你也有帮助。