iOS 8 Xcode 6:灰色约束有什么意义?

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

iOS 8 Xcode 6: What's the point of the grayed out constraints?

iosxcodeios8xcode6

提问by RyJ

In the Xcode 6 betas, when I delete a constraint, it doesn't remove it completely, but grays it out. I thought that was to imply that the constraint was used in a different size class, but that doesn't seem to be the case. Also, how do you permanently delete these constraints?

在 Xcode 6 betas 中,当我删除一个约束时,它不会完全删除它,而是将它变灰。我认为这意味着该约束用于不同的大小类,但情况似乎并非如此。另外,如何永久删除这些约束?

采纳答案by Ricky

There are a few ways to delete the constraints from the Storyboard

有几种方法可以从 Storyboard 中删除约束

  1. Try not to delete from the Storyboard object because sometimes different constraints can stack together and you might delete the wrong one. So, it is better to delete from the Document Outline. Just highlight the constraint that you want to delete on the Document Outlineand just press deletebutton on your keyboard. See screen shot below: enter image description here

  2. If you want to clear all the constraints from a selected view, Select the View (eg: A button), Tap on the Third Button (Resolve Auto Layout Issues Button), Tap Clear Constraints. enter image description here

  3. If you want to clear all the constraints for all the views inside the view controller, Highlight the right view controller Object inside the storyboard, Tap on the Third Button (Resolve Auto Layout Issues Button), Tap Clear Constraintsunder the "All Views in the View Controller".

  1. 尽量不要从 Storyboard 对象中删除,因为有时不同的约束会堆叠在一起,您可能会删除错误的约束。因此,最好从Document Outline 中删除。只需在文档大纲上突出显示要删除的约束,然后按键盘上的删除按钮即可。请参阅下面的屏幕截图: 在此处输入图片说明

  2. 如果要清除选定视图中的所有约束,请选择视图(例如:A 按钮),点击第三个按钮(解决自动布局问题按钮),点击清除约束在此处输入图片说明

  3. 如果要清除视图控制器中所有视图的所有约束,请在故事板中突出显示正确的视图控制器对象,点击第三个按钮(解决自动布局问题按钮),点击“所有视图中的所有视图”下的清除约束视图控制器”。

回答by greatchi

Double click the grayed out constraint (switches focus to the constraint) then press delete. This will delete the constraint.

双击变灰的约束(将焦点切换到约束)然后按删除。这将删除约束。

回答by Sam

I believe the answer to the following question is that you can have same constraint selectively "installed" (or to my understanding, enabled) for different size classes. After you select a constraint from Document Outline, you can click on the + sign to Add Size Class Customization from the bottom of Attribute Inspector. So when you delete a constraint from the Size Inspector, you're basically deleting a constraint for a particular size class only. In order to delete a constraint for all size classes, you have to delete from Document Outline.

我相信以下问题的答案是,您可以为不同的尺寸类别有选择地“安装”(或据我所知,启用)相同的约束。从文档大纲中选择约束后,您可以单击 + 号以从属性检查器底部添加尺寸类自定义。因此,当您从 Size Inspector 中删除约束时,您基本上只是删除了特定尺寸类的约束。为了删除所有尺寸类的约束,您必须从文档大纲中删除。

Why? Why can't you completely delete a constraint from the size inspector?!

为什么?为什么不能从尺寸检查器中完全删除约束?!

回答by RyJ

You can not delete grayed out constraints from the right hand Size Inspector (which is where I normally delete constraints because it's much easier to ascertain which view the constraints are for, it get's really confusing in the Document Outline), but you can delete the same grayed out constraints from the Document Outline on the left by selecting them and hitting the delete button.

您无法从右侧的 Size Inspector 中删除变灰的约束(这是我通常删除约束的地方,因为确定约束针对哪个视图要容易得多,它在文档大纲中真的很混乱),但您可以删除相同的通过选择它们并点击删除按钮,使左侧文档大纲中的约束变灰。

Example of grayed out constraint (see height):

变灰约束的示例(参见高度):

enter image description here

在此处输入图片说明

Note:To make the Document Outline's constraints easier to digest, I first delete them from the Size Inspector, which grays them out, then delete the newly grayed out constraint from the Size Inspector. Just FYI.

注意:为了使文档大纲的约束更容易理解,我首先从大小检查器中删除它们,这会使它们变灰,然后从大小检查器中删除新变灰的约束。仅供参考。

回答by Meseery

That's because of size classes, you can disable size classes from File Inspector and every greyed constraints runs out, you can re-enable them again if you need them.

那是因为大小类,您可以从文件检查器中禁用大小类,并且每个灰色约束都用完,如果需要,您可以再次重新启用它们。

Hope it helps

希望能帮助到你