ios Xcode Storyboard 警告:约束引用项在当前配置中已关闭。在当前配置中关闭此约束

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

Xcode Storyboard warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration

iosxcodecocoa-touchstoryboardxcode6

提问by Zhihao Yang

This warning happens in Xcode 6.1. Anyone have ideas what does this warning mean and what will happen with it? Many thanks!

此警告发生在 Xcode 6.1 中。任何人都知道这个警告是什么意思以及它会发生什么?非常感谢!

Below is a screenshot with the warnings opened in source code"

以下是在源代码中打开警告的屏幕截图”

enter image description here

在此处输入图片说明

How to find which constraint causes the warning? Xcode does not tell you which constraint is the problem.

如何找到导致警告的约束?Xcode 不会告诉您哪个约束是问题。

enter image description here

在此处输入图片说明

回答by BastiBen

This warning can be annoying and happens as of Xcode 6.1.1. The main problem is that you can not easily find the referenced constraint by clicking on the warning. I guess this is a bug and will get fixed sooner or later.

这个警告可能很烦人,从 Xcode 6.1.1 开始就会发生。主要问题是您无法通过单击警告轻松找到引用的约束。我想这是一个错误,迟早会得到修复。

However, in the meantime you can use this little workaround:

但是,与此同时,您可以使用这个小解决方法:

Step 1: Detect annoying warning

第 1 步:检测烦人的警告

Annoying warning

烦人的警告

Step 2: Right/Ctrl-Click on warning, select Reveal in Log

步骤 2:右键/Ctrl-单击警告,选择 Reveal in Log

enter image description here

在此处输入图片说明

Step 3: Admire the beauty of the following log snippet:

第 3 步:欣赏以下日志片段的美妙之处:

... snip ...
/Devel/MyCrippledAppNG/MyCrippledApp/Main_iPad.storyboard:Dlb-cb-nWC: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
/Devel/MyCrippledAppNG/MyCrippledApp/Main_iPad.storyboard:6Ze-mO-v5N: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
/Devel/MyCrippledAppNG/MyCrippledApp/Main_iPad.storyboard:9av-xw-u1o: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
/Devel/MyCrippledAppNG/MyCrippledApp/Main_iPad.storyboard:RPt-Uf-vaZ: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
/Devel/MyCrippledAppNG/MyCrippledApp/Main_iPad.storyboard:Rnc-4M-7jV: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
/Devel/MyCrippledAppNG/MyCrippledApp/Main_iPad.storyboard:epJ-D9-KEF: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
/Devel/MyCrippledAppNG/MyCrippledApp/Main_iPad.storyboard:4HC-Gu-01w: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
... snip ...

Hmmm... What's this...?

嗯……这是什么……?

interesting

有趣的

Step 4: Let's toss that into the project search bar...

第 4 步:让我们将其放入项目搜索栏中...

search

搜索

Yep, you guessed right. Click it.

是的,你猜对了。点击它。

Step 5: OMG! Enjoy a few extra minutes of productivity until Apple fixes this annoying bug.

第 5 步:天哪!在 Apple 修复这个烦人的错误之前,多享受几分钟的工作效率。

wheeee

呜呜呜



For 2016...

对于 2016 年...

  • If you can't get it with 'Reveal in Log', show the Report Navigator. (That is the rightmost tab on the leftmost column.) Delve into the build results there. That will show the build log, including the constraint ID. courtesy buildsucceeded
  • 如果您无法通过“在日志中显示”获得它,请显示报告导航器。(这是最左侧列中最右侧的选项卡。)深入了解那里的构建结果。这将显示构建日志,包括约束 ID。礼貌构建成功

enter image description here

在此处输入图片说明

enter image description here

在此处输入图片说明

  • Note that for Xcode of 5/2016, annoyingly you have to quit and restartXcode to clear this warning in some cases.

  • Note that confusingly, the same error can be caused by an unrelated problem (this appears to be an Apple bug or poor use of error language): if you have IBInspectableitems, and happen to renamethem in your Swift files. Xcode does notdelete the old-name UserDefinedRuntimeAttributes for you. Simply click to "Identity Inspector" (item 3 on right panel) and delete the dud items.

  • 请注意,对于 5/2016 的Xcode,在某些情况下,您必须退出并重新启动Xcode 才能清除此警告,这很烦人。

  • 请注意,令人困惑的是,相同的错误可能是由不相关的问题(这似乎是 Apple 错误或错误语言使用不当)引起的:如果您有IBInspectable项目,并且碰巧在您的 Swift 文件中重命名了它们。Xcode中并没有删除旧名UserDefinedRuntimeAttributes为您服务。只需单击“身份检查器”(右侧面板上的项目 3)并删除无用项目。

For 2017...

对于 2017 年...

  • Yet another common, and indeed simpler, cause of the problem. If you happened to un-Installan item: As of writing, very simply Xcode does not know to automatically also uninstall any constraints which lead to that item. Quite simply, look at any un-Installed items, and for all of its constraints, just mark them un-Installed. (Or simply, perhaps just temporarily delete the un-Installed item altogether, to see if that's the problem.)
  • 问题的另一个常见且确实更简单的原因。如果您碰巧卸载了一个项目:在撰写本文时,很简单,Xcode不知道自动卸载导致该项目的任何约束。很简单,查看任何未安装的项目,对于它的所有约束,只需将它们标记为未安装。(或者简单地说,也许只是暂时完全删除未安装的项目,看看这是否是问题所在。)

回答by KPM

This message is triggered when you have deactivated a view in your storyboard, but didn't deactivate the constraints based on that view.

当您停用故事板中的视图,但未停用基于该视图的约束时,会触发此消息。

For example, you deactivated a button, but you still have some constraints linked to that button. It may be an intrinsic constraint like height or width, or a relative constraint like the distance from another view.

例如,您停用了一个按钮,但您仍然有一些与该按钮相关联的约束。它可能是高度或宽度等内在约束,也可能是与另一个视图的距离等相对约束。

You have to turn off each of the constraints referencing the view, and you have to do it manually. Xcode is being overconservative here and won't do it for you.

您必须关闭引用视图的每个约束,并且必须手动执行此操作。Xcode 在这里过于保守,不会为您效劳。

回答by Zhihao Yang

This solution works for me.

这个解决方案对我有用。

Because I copied several items from the project I developed in Xcode 5 into Xcode 6, and the storyboard in Xcode 6 supports multiple layouts, for every constraint, I need to install it in the current configuration.

因为我把我在Xcode 5开发的项目中的几个项目复制到了Xcode 6中,并且Xcode 6中的storyboard支持多种布局,所以对于每个约束,我都需要在当前配置中安装它。

For example, I am using "Compact Width | Regular Height", for the constraint I need to set like below:

例如,我正在使用“紧凑宽度 | 常规高度”,对于我需要设置的约束,如下所示:

enter image description here

在此处输入图片说明

After I checked and set all the hundreds of constraints in my projects, clean and build, the warnings finally disappear.

在我检查并设置项目中的所有数百个约束、清理和构建之后,警告终于消失了。

回答by Dirk

Just wanted to add my case how this Error happened for me: In my case, I wanted to delete a Textfield with "Cmd+Backspace". I did this directly in the Scene-Builder Tree-View:

只是想添加我的案例,这个错误是如何发生在我身上的:就我而言,我想删除一个带有“Cmd+Backspace”的文本字段。我直接在 Scene-Builder Tree-View 中做了这个:

enter image description here

在此处输入图片说明

You can see that the snooze Field is grayed out.

您可以看到贪睡字段变灰了。

So that was easily discovered for me. You can than simply really delete the Field by selecting:

所以这对我来说很容易发现。您可以通过选择来简单地真正删除该字段:

Edit-Delete from the Menu

从菜单编辑-删除

Surprisingly - this really deletes the field (including the constraints). Maybe this helps someone to easily find the cause of this annoying Warning...

令人惊讶的是 - 这确实删除了该字段(包括约束)。也许这有助于某人轻松找到这个烦人的警告的原因......

回答by Tommie C.

Expanded Explanation

扩展说明

Nothing wrong with the other answers. I just wanted to draw attention to the wordingin the original warningand to identify a couple of use-cases where this can show up in one's workflow.

其他答案没有错。我只是想提请注意原始警告中措辞,并确定几个用例,这些用例可能会出现在一个人的工作流程中。

constraint-warning

约束警告

Constraint referencing items turned off in current configuration.

在当前配置中关闭了约束引用项。

Meaning that some item (usually a control or custom view that is normally visible) referenced in one or more constraints is turned off (disabled or has the checkbox "installed" unchecked). If for example you decide that you want to move a control or view in your storyboard outside of the main view (or you may see sometimes when doing something interesting in size classes) then you may see this warning if the control has constraints attached to it.

这意味着在一个或多个约束中引用的某些项目(通常是通常可见的控件或自定义视图)被关闭(禁用或未选中“安装”复选框)。例如,如果您决定将故事板中的控件或视图移动到主视图之外(或者有时您可能会在大小类中做一些有趣的事情时看到),那么如果控件附加了约束,您可能会看到此警告.

uninstalled-control

卸载控件

Along with the recommended solution:

连同推荐的解决方案:

Turn off this constraint in the current configuration.

在当前配置中关闭此约束。

Two Approaches to Fix

两种修复方法

Document Outline

文件大纲

Visually you can open the Document Outline in your storyboard and look for the grayed out Constraints that reference your control/view sitting outside of the main view (widen the outline, click the constraint, and view the attributes inspector, mouse down to review fast). Then remove the constraint from this context (size class). For example, in my case I am just holding the control until I decide later where to present it, so I chose to delete completely the offending constraint until later. But in a size class I would just uninstall the constraint from the current context using the installed checkbox in the attributes inspector.

在视觉上,您可以在故事板中打开文档大纲,并查找引用位于主视图之外的控件/视图的灰色约束(加宽大纲,单击约束,然后查看属性检查器,向下移动鼠标以快速查看) . 然后从此上下文中删除约束(大小类)。例如,在我的例子中,我只是持有控制权,直到我决定以后在哪里展示它,所以我选择在以后完全删除有问题的约束。但是在大小类中,我只需使用属性检查器中的已安装复选框从当前上下文中卸载约束。

Log Navigator/Find Tool

日志导航器/查找工具

One can also continue to use the Log Navigator to find the problem control via the unique identifier given to each object on the storyboard. In the log it would be just before the yellow highlighted text and typically takes the form as seen in my example above: jvj-mY-DHf

还可以继续使用 Log Navigator 通过为故事板上的每个对象提供的唯一标识符来查找问题控件。在日志中,它就在黄色突出显示的文本之前,通常采用上面示例中所示的形式:jvj-mY-DHf

Using the identifier one can then use the find tool in Xcode to locate and delete (completely) or uninstall (for the current context) the offending constraint.

使用标识符,然后可以使用 Xcode 中的查找工具来定位和删除(完全)或卸载(对于当前上下文)有问题的约束。

log-navigator

日志导航器

If you're fond of Xml and its simplicity you can also just open up the Storyboard as Source Code and find the offending unique identifier and delete the appropriate block of xml.

如果您喜欢 Xml 及其简单性,您还可以将 Storyboard 作为源代码打开,找到有问题的唯一标识符并删除相应的 xml 块。

回答by Jano

One of the reasons this could happen is because you selected a size class not compatible with your constraints (wAny hAnyis a common case). In such case, just select a different size class in Interface Builder and you are done.

这可能发生的原因之一是因为您选择了与您的约束不兼容的尺寸类(这wAny hAny是一种常见情况)。在这种情况下,只需在 Interface Builder 中选择不同的大小类即可。

回答by Ryde

For me, it happens if I set an object a new contraint to object (not view) with "Constraint to margins" option not ticked. Problem solved with tick the option (which is default).

对我来说,如果我将一个对象设置为一个新的约束对象(不是视图),并且没有勾选“约束到边距”选项,就会发生这种情况。问题通过勾选选项解决(这是默认设置)。

回答by Scooter

What worked for me (and I have no idea why) is to turn "Use Trait Variations" off, then perform a clean, then turn them back on. The next build had no warnings.

对我有用的(我不知道为什么)是关闭“使用特征变化”,然后执行清理,然后重新打开它们。下一个构建没有警告。

To turn off "Use Trait Variations" simply select your storyboard in the Project Navigator and then select File Inspector.

要关闭“Use Trait Variations”,只需在 Project Navigator 中选择您的故事板,然后选择 File Inspector。

enter image description here

在此处输入图片说明

Then just deselect "Use Trait Variations", perform clean by pressing Shift-CMD K, and then turn trait variations back on if you want to use them.

然后只需取消选择“使用特征变体”,按 Shift-CMD K 执行清理,然后如果您想使用特征变体,则重新打开它们。

enter image description here

在此处输入图片说明

回答by George Filippakos

I had the problem on a stack view. Deleting the constraints and re-adding them did not help. Cleaning and rebuilding did not help.

我在堆栈视图上遇到了问题。删除约束并重新添加它们没有帮助。清洁和重建没有帮助。

For me, the solution was to create a completely new stack view object.

对我来说,解决方案是创建一个全新的堆栈视图对象。

Then move all elements from the old stack view into the new stack view.

然后将旧堆栈视图中的所有元素移动到新堆栈视图中。

Deleting the old stack view fixed the problem.

删除旧的堆栈视图解决了这个问题。

回答by Chuckles

I thought it was a persisting constraint due to the other answer, however it was due to an 'outlet' I still had for an item I deleted before. What to do is:

由于另一个答案,我认为这是一个持久性约束,但这是由于我之前删除的项目仍然有一个“出口”。要做的是:

  1. Select your ViewController
  2. Click on the 'outlet' icon on the top right
  3. Look through your outlets and carefully delete any that you don't need
  1. 选择您的视图控制器
  2. 点击右上角的“插座”图标
  3. 查看您的网点并仔细删除您不需要的任何网点

Worst case scenario you delete all your outlets and just hook them up again. Case solved!

最坏的情况是您删除所有网点,然后重新连接它们。案子破了!