如何(轻松)删除 Xcode 6 中 Interface Builder 中的约束
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/24292514/
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
How do I (easily) delete a constraint in Interface Builder in Xcode 6
提问by DBD
Assume you've selected an object and you have the Size Selector in the Utilities panel open. You can see the list of constraints applied to the object. In the list of constraints you could click on the little gear and pick delete. You can't in Xcode 6.
假设您已经选择了一个对象并且您打开了“实用工具”面板中的“大小选择器”。您可以看到应用于对象的约束列表。在约束列表中,您可以单击小齿轮并选择删除。你不能在 Xcode 6 中。
There are still several ways to delete constraints in IB:
IB中删除约束的方法还有以下几种:
- Find the constraint in the Document Outline and delete it that way (but it can be hard to find).
- Click on the little bar in the storyboard and delete it that way (which can be hard to click on).
- Double click on the constraint in the Size Selector which will open Attribute Inspector and highlight the constraint in the Document Outline. This can be a nuisance when you want to delete several.
- 在文档大纲中找到约束并以这种方式将其删除(但可能很难找到)。
- 单击情节提要中的小栏并以这种方式将其删除(可能很难单击)。
- 双击大小选择器中的约束,这将打开属性检查器并突出显示文档大纲中的约束。当您要删除多个时,这可能会很麻烦。
Still, I miss ease of use of the gear delete feature and I'm wondering if it's still there in a similar fashion and I just can find it. While the other ways work, I find myself wasting lots of time especially when playing with the new Size Classes feature. So, find a easier way to delete them?
尽管如此,我还是想念齿轮删除功能的易用性,我想知道它是否仍然以类似的方式存在,我只能找到它。虽然其他方法有效,但我发现自己浪费了大量时间,尤其是在使用新的 Size Classes 功能时。那么,找到一种更简单的方法来删除它们吗?
回答by Paul Patterson
In Xcode6 (Beta5) when I click on a particular constraint in the Size inspector, it acquires a thin blue border. The constraint can then be deleted using the backspace.
在 Xcode6 (Beta5) 中,当我单击大小检查器中的特定约束时,它会获得一个蓝色的细边框。然后可以使用退格键删除约束。
回答by DanSkeel
The accepted answer is right, but there is so much frustration with selecting constraints that lay outside of selected viewthat I decided to add this tips as another answer.
接受的答案是正确的,但是选择位于所选视图之外的约束非常令人沮丧,因此我决定将此提示添加为另一个答案。
I found incredible list of tipsthat helped me to solve this problem.
The problem:
问题:
- You select the view and Xcode shows related constraints.
- You try to choose the one that is outside of selected view.
- You fail (end with selecting the view beneath the constraint)
- 您选择视图,Xcode 会显示相关约束。
- 您尝试选择所选视图之外的那个。
- 您失败了(以选择约束下方的视图结束)
Soulution:
解决方案:
Click it with Shift+Ctrlpressed and you'll see a menu of all the views that exist where you've clicked.
按下Shift+Ctrl键单击它,您将看到一个菜单,其中包含您单击的所有视图。
To delete selected constraint press deletekey.
要删除选定的约束,请按delete键。
回答by kakubei
The selected answer is incomplete. When you delete the constraint from the Size Inspector, you are leaving behind the constraint object in the Document Outline pane. It is greyed out, meaning it is not used, but still exists and, what's worse, will affect auto layout with errors, warnings or conflicting constraints and you will go crazy until you also delete them from the Document Outline pane.
所选答案不完整。当您从 Size Inspector 中删除约束时,您将在 Document Outline 窗格中留下约束对象。它是灰色的,意味着它没有被使用,但仍然存在,更糟糕的是,它会影响自动布局并出现错误、警告或冲突的约束,你会发疯,直到你也从“文档大纲”窗格中删除它们。
So:
所以:
1. Delete the constraint from the Size Inspector as in the accepted answer
2. Delete any greyed out constraints from the Document Outline
Live a happy, constraint-free life.
过着快乐、无拘无束的生活。
回答by Crashalot
This answer from @wayne chiis the simplest, and spares you from hunting down constraints in Document Outline:
@wayne chi 的这个答案是最简单的,让您无需在文档大纲中寻找约束条件:
Double click the grayed out constraint (switches focus to the constraint) then press delete. This will delete the constraint.
双击变灰的约束(将焦点切换到约束)然后按删除。这将删除约束。
回答by ma11hew28
Sometimes, the easiest way is to close the file in Xcode and edit it with a text editor. :-/
有时,最简单的方法是在 Xcode 中关闭文件并使用文本编辑器进行编辑。:-/
回答by FierceMonkey
If you want to delete ALL constraints from a viewController simply turn off auto layout and then reenable it (or don't) and all of the constraints will be gone.
如果您想从 viewController 中删除所有约束,只需关闭自动布局,然后重新启用(或不启用),所有约束都将消失。