8.0 之前的 iOS 版本上相对于布局边距的布局属性
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25261326/
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
Layout attributes relative to the layout margin on iOS versions prior to 8.0
提问by Andy
What would be causing the following warning (and subsequent alignment issues on iOS 7)?
什么会导致以下警告(以及 iOS 7 上的后续对齐问题)?
Attribute Unavailable: Layout attributes relative to the layout margin on iOS versions prior to 8.0
属性不可用:在 8.0 之前的 iOS 版本上,布局属性相对于布局边距
采纳答案by Andy
Disable "Prefer margin relative"
禁用“首选保证金相对”
回答by Legoless
None of the posted answers solved the problem for me. But the reason for this is the following: Xcode 6 creates constraints based on relative margins by default.Those are only available on iOS 8.0 and newer. You get these warnings when your deployment target is set to iOS 7.0 or lower.
发布的答案都没有为我解决问题。但原因如下:Xcode 6 默认基于相对边距创建约束。这些仅适用于 iOS 8.0 及更高版本。当您的部署目标设置为 iOS 7.0 或更低版本时,您会收到这些警告。
The way I fixed the warning:
我修复警告的方式:
- Click the warning in Xcode
- Attribute inspector will open the constraint
- Search for item that has margin (see screenshot)
- Turn off Relative to marginoption
- 单击 Xcode 中的警告
- 属性检查器将打开约束
- 搜索有边距的项目(见截图)
- 关闭相对于保证金选项
回答by Matt R
Unchecking the "Prefer Margin Relative" checkbox will keep you from getting into the situation where you get this warning.
取消选中“Prefer Margin Relative”复选框将防止您陷入收到此警告的情况。
If you are like me and you built an entire app with constraints before realizing the problem, then things are a bit tougher because Xcode will not easily tell you which constraints are a problem.
如果你像我一样,在意识到问题之前用约束构建了一个完整的应用程序,那么事情就有点困难了,因为 Xcode 不会轻易告诉你哪些约束是问题。
In order to avoid rebuilding all of my constraints, I resorted to looking at the actual .storyboard file and I looked for constraints like this:
为了避免重建我的所有约束,我求助于查看实际的 .storyboard 文件,我寻找这样的约束:
<constraint firstItem="vId-..." firstAttribute="top" secondItem="In7-..." secondAttribute="topMargin" id="C0H-..."/>
Notice "topMargin". The attributes ending in "Margin" cause the warning. I went through and identified the constraints in the file this way, then I removed and re-created them in IB. After that, this warning went away.
注意“topMargin”。以“Margin”结尾的属性会导致警告。我通过这种方式检查并确定了文件中的约束,然后我在 IB 中删除并重新创建了它们。之后,这个警告就消失了。
I suspect this should also resolve some inconsistencies between iOS 7 and iOS 8 constraint handling, although I am still encountering some differences in behavior, even after addressing all Xcode warnings.
我怀疑这也应该解决 iOS 7 和 iOS 8 约束处理之间的一些不一致,尽管我仍然遇到一些行为差异,即使在解决了所有 Xcode 警告之后。
回答by Jonathan Arbogast
I'm currently in the same situation as I'm creating an app in Xcode 6 that targets iOS7 and 8. That warning appears because the constraints relative to the margin aren't available in iOS7, but they are created by default in Xcode 6.
我目前处于相同的情况,因为我在 Xcode 6 中创建了一个针对 iOS7 和 8 的应用程序。出现该警告是因为相对于边距的约束在 iOS7 中不可用,但它们是在 Xcode 6 中默认创建的.
You can absolutely go back and edit the constraint to not use that 'Relative to margin' feature as suggested by the other answers to this question.
您绝对可以返回并编辑约束,以不使用该问题的其他答案所建议的“相对于保证金”功能。
When creating new constraints, I hold down the Option key when choosing which kind of constraint to create. This gives me the ability to create a constraint that's not based on the margin right away so I don't have to go back and fix it afterwards.
创建新约束时,我在选择要创建的约束类型时按住 Option 键。这使我能够立即创建不基于边距的约束,因此我不必事后返回并修复它。
回答by skywinder
Xcode 6 creates constraints based on relative margins by default.
默认情况下,Xcode 6 基于相对边距创建约束。
So, if you want to force remove all baselines attributes and don't want to search all bad constrains in Interface Buidler, to support iOS 7, I can recommend this way
因此,如果您想强制删除所有基线属性并且不想在 Interface Buidler 中搜索所有不良约束,以支持iOS 7,我可以推荐这种方式
To find and remove all dummy strings with "Baseline" in constraints you can do this:
要查找并删除约束中带有“基线”的所有虚拟字符串,您可以执行以下操作:
- Close Xcode
- Open your stroyboard file in your favorite text editor, that supports regexp.
- Find and remove from storyboard file all strings by pattern:
.*"baseline".*\n
- Now save file and open it in Xcode
- Fix all appeared misaligns: find all warnings and press "Update constraints for all views" to save original position of all views.
- Profit!
- 关闭 Xcode
- 在您喜欢的支持正则表达式的文本编辑器中打开您的 stroyboard 文件。
- 按模式查找并从故事板文件中删除所有字符串:
.*"baseline".*\n
- 现在保存文件并在 Xcode 中打开它
- 修复所有出现的未对齐:查找所有警告并按“更新所有视图的约束”以保存所有视图的原始位置。
- 利润!
UPD:I found that "baseline" constraints causes crashes also, but Xcode doesn't show any warnings about these constrains!
UPD:我发现“基线”约束也会导致崩溃,但 Xcode 没有显示关于这些约束的任何警告!
To fix it - remove from storyboard file all strings by pattern: .*"baseline".*\n
要修复它 - 按模式从故事板文件中删除所有字符串: .*"baseline".*\n
回答by ShakeMan
I took a non programmer approach.
我采用了非程序员的方法。
I knew which view controler was causing the 8.0 margin message. So, I went to my constraint list. I had 33. I've remove every one that was causing the 8.0 margin message. I went down to 20 (So 11 was problem).
我知道哪个视图控制器导致了 8.0 边距消息。所以,我去了我的约束列表。我有 33 个。我已经删除了导致 8.0 保证金消息的每个。我降到了 20(所以 11 是问题)。
Select 32 over 33 delete and see the result. Select 31 over 33 delete and so on ... Naturally when the message still there ... delete the problematic one.
选择32 over 33 delete,看看结果。选择 31 过 33 删除等等...自然当消息还在那里时...删除有问题的。
So it took me 5 minutesto resolve the error message.
所以我花了5 分钟来解决错误消息。
Other constraint messages did appear but that's not a big deal.
确实出现了其他约束消息,但这没什么大不了的。
Ok than, redo and resolve step by step the constraint messages but this time check that all the constraint you add don't provoke the reappearing of the 8.0 margin message. If so, undo and take an other strategy when adding constraints. There's always an other way to add a constraint that work.
好的,重做并逐步解决约束消息,但这次检查您添加的所有约束都不会引起 8.0 保证金消息的重新出现。如果是这样,请在添加约束时撤消并采取其他策略。总有另一种方法可以添加有效的约束。
That's not what is proposed by Xcode but it will do the job.
这不是 Xcode 提出的,但它会完成这项工作。
At the end, your done.
最后,你完成了。
If you have more than one view controller, and don't know witch one is causing the 8.0 margin message, try to isolate each view controller. May be in a separate test project with a copy and paste or deleting all the other view except one and se the result.
如果您有多个视图控制器,并且不知道是哪个导致了 8.0 边距消息,请尝试隔离每个视图控制器。可能在一个单独的测试项目中复制和粘贴或删除除一个视图之外的所有其他视图并设置结果。
Using the "Create Snapshot" in the file menu can help you if something goes wrong.
如果出现问题,使用文件菜单中的“创建快照”可以帮助您。
回答by ObjectiveTC
Suppressing the warnings: I went through all IB constraints and deleted all that said "First Baseline...". This made all of these warnings go away. However, IB will reintroduce the warnings if you "Add missing constraints" or "reset to suggested constraints".
抑制警告:我经历了所有 IB 约束并删除了所有说“第一基线......”的内容。这使得所有这些警告都消失了。但是,如果您“添加缺少的约束”或“重置为建议的约束”,IB 将重新引入警告。
Possible cause: From a fresh Xcode 6.1 project, I copy/pasted ViewControllers in Storyboard (lazily), using "reset to suggested constraints". Then changed the project target from 8.0 to 7.1. This caused the warnings to pop up. I noticed that the warnings only occurred on certain of my ViewControllers, which I believe were the ones I copied/pasted in Storyboard.
可能的原因:从一个新的 Xcode 6.1 项目中,我使用“重置为建议的约束”在 Storyboard 中(懒惰地)复制/粘贴了 ViewControllers。然后将项目目标从 8.0 更改为 7.1。这导致警告弹出。我注意到警告只发生在我的某些 ViewControllers 上,我相信这是我在 Storyboard 中复制/粘贴的那些。
Suggestion: If targeting 7.1, set it up front before using IB. Don't copy/paste view controllers in Storyboard. And be wary of "new warnings" when working within IB, so hopefully we can confirm the cause of this annoyance.
建议:如果面向 7.1,请在使用 IB 之前预先设置。不要在 Storyboard 中复制/粘贴视图控制器。并且在 IB 中工作时要警惕“新警告”,所以希望我们能确认这种烦恼的原因。