Xcode 8. 约束引用项在当前配置中关闭
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/40057412/
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 8. Constraint referencing items turned off in current configuration
提问by Danny
I've faced with the problem after updating to Xcode 8. Every time after UI objects are deleted from the main storyboard I get the following warning:
更新到 Xcode 8 后,我遇到了这个问题。每次从主故事板中删除 UI 对象后,我都会收到以下警告:
Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
在当前配置中关闭了约束引用项。在当前配置中关闭此约束。
It looks like this is an Xcode bug, but anyway I want to remove these warnings from the project. I found that there were the same problem with Xcode 6 herebut no answer from that question fix the problem right no. So when I find the incorrect constraint in the storyboard and delete it the amount of incorrect constrains is increasing instead of decreasing. I things that I've also tried:
看起来这是一个 Xcode 错误,但无论如何我想从项目中删除这些警告。我发现这里的Xcode 6 也存在同样的问题,但该问题的答案没有解决问题。因此,当我在故事板中找到不正确的约束并将其删除时,错误约束的数量会增加而不是减少。我也尝试过的事情:
- cleaned the project
- cleaned the derived data
- deleted all constraints and added new ones from the scratch
- 清理了项目
- 清洗派生数据
- 删除所有约束并从头开始添加新约束
Any ideas?
有任何想法吗?
回答by AamirR
I was having several views that were not Installed
, after updating to xcode 8.1, I had 2 warnings.
我有几个不是的视图,Installed
更新到 xcode 8.1 后,我收到了 2 个警告。
Following steps worked for me:
以下步骤对我有用:
1) Clean the project and restart Xcode, warnings decreased to 1.
1)清理项目并重新启动Xcode,警告减少到1。
2) Selecting the warning will show exactly which constraint having an issue. Open Attributes Inspector
and select those views where constraint is applied, look for Installed
if its unchecked on the view (not on constraint). You can either select Installed on the view, or unselect Installed on constraint itself.
2) 选择警告将准确显示哪个约束有问题。打开Attributes Inspector
并选择那些应用了约束的视图,查看Installed
它是否在视图上未选中(而不是在约束上)。您可以选择安装在视图,或取消选择安装在约束自己。
See screenshot below. Installed
was unchecked on view, not on the constraint that the warning was pointing to :)
请参阅下面的屏幕截图。Installed
在视图中未选中,而不是在警告指向的约束上:)
Update: Same issue again with another ViewController, a UIView was not Installed for a size class, I unselect Installed on constraint itself and warning is gone too, I guess its not an Xcode bug, its claiming to turn Installed on/off on both UIView and Constrarint
更新:另一个 ViewController 又出现了同样的问题,没有为大小类安装 UIView,我取消了约束本身的安装,警告也消失了,我猜这不是 Xcode 错误,它声称在两个 UIView 上都打开/关闭了安装和约束
回答by jungledev
The short answer: Inspect the source code for your storyboard for each of the ids in your warnings by searching 'id="theIdFromWarning". The ids are for the constraints. When you find the constraint id, it will reference the two element ids. Search for the elements by searching 'id="theIdForElement"' Then you'll find the name or some piece of info in that element source code to find out what element you're looking at. Then switch the storyboard back from source code to the interface builder, find the two elements, and see which size class the related constraint is installed but the element isn't. Example: ViewA.right could be horizontally constrained to ViewB.left, installed on all size classes, but ViewA might only be installed on height=Regular size class. Solution: Install ViewA on all size classes, or uninstall the constraint on all size classes and add the constraint to only the height=Regular size class.
简短的回答:通过搜索 'id=" theIdFromWarning"检查警告中每个 ID 的故事板的源代码。id 用于约束。当您找到约束 id 时,它将引用两个元素 id。通过搜索 'id=" theIdForElement来搜索元素"' 然后你会在那个元素的源代码中找到名称或一些信息来找出你正在查看的元素。然后将故事板从源代码切换回界面构建器,找到这两个元素,然后看看安装了哪个尺寸等级的相关约束,但没有安装元素。例如:ViewA.right 可以水平约束到 ViewB.left,安装在所有尺寸等级上,但 ViewA 可能只安装在 height=Regular 尺寸等级上。解决方案:在所有尺寸等级上安装 ViewA,或者卸载所有尺寸等级上的约束并仅将约束添加到 height=Regular 尺寸等级。
Longer answer, step-by-step:
更长的答案,一步一步:
I was not able to easily see what constraints/elements these warnings were referring to. For me, I was able to right click the warning, and select "Reveal in log". This revealed 10 warnings in this style format:
我无法轻松查看这些警告所指的约束/元素。对我来说,我可以右键单击警告,然后选择“在日志中显示”。这显示了这种样式格式的 10 个警告:
/my/filepath/to/storyboard:1xe-xx-Bx5: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
/my/filepath/to/storyboard:1xe-xx-Bx5: warning: Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
If your log doesn't show a detailed description like this, then right-click on any log reference to Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
warning and select Expand all transcripts
, then search your log file for the constraint descriptions.
如果您的日志没有显示这样的详细描述,则右键单击任何对Constraint referencing items turned off in current configuration. Turn off this constraint in the current configuration.
警告的日志引用并选择Expand all transcripts
,然后在您的日志文件中搜索约束描述。
So, I opened my storyboard, right clicked the storyboard file in the project navigator and selected 'view as source code' searched for every constraint by the listed id (in the above example, I searched for the id:1xe-xx-Bx5), and found one reference to it:
因此,我打开我的故事板,右键单击项目导航器中的故事板文件,然后选择“作为源代码查看”,通过列出的 id 搜索每个约束(在上面的示例中,我搜索了 id:1xe-xx-Bx5) ,并找到了对它的一个参考:
<constraint firstItem="Mwb-6O-DKs" firstAttribute="top" secondItem="y2M-Sk-Ygh" secondAttribute="bottom" constant="19" id="1ce-xx-Bx5"/>
<constraint firstItem="Mwb-6O-DKs" firstAttribute="top" secondItem="y2M-Sk-Ygh" secondAttribute="bottom" constant="19" id="1ce-xx-Bx5"/>
What this tells me is:
这告诉我的是:
- That the constraint has an id of 1ce-xx-Bx5
- The constraint is associated with two elements:
- One has the id of Mwb-6O-DKs
- The other has the id of y2M-Sk-Ygh
- 约束的 id 为1ce-xx-Bx5
- 该约束与两个元素相关联:
- 一个有Mwb-6O-DKs的 id
- 另一个的 id 为y2M-Sk-Ygh
So I searched the source code for the first element by id, by searching for id="Mwb-6O-DKs"
and found this:
所以我通过 id 搜索第一个元素的源代码,通过搜索id="Mwb-6O-DKs"
并找到了这个:
<label ...(truncating for readability sake)...text="Build Label"...(truncating for readability sake)...id="Mwb-6O-DKs">
<label ...(truncating for readability sake)...text="Build Label"...(truncating for readability sake)...id="Mwb-6O-DKs">
This tells me that the first element is a UILabel
with the title 'Build Label'.
这告诉我第一个元素是UILabel
标题为“Build Label”的元素。
Searching for the second element by id, id="y2M-Sk-Ygh"
, revealed:
通过 id 搜索第二个元素id="y2M-Sk-Ygh"
,显示:
<viewController storyboardIdentifier="login"...(truncating for readability sake)...<layoutGuides><viewControllerLayoutGuide type="top" id="y2M-Sk-Ygh"/>
<viewController storyboardIdentifier="login"...(truncating for readability sake)...<layoutGuides><viewControllerLayoutGuide type="top" id="y2M-Sk-Ygh"/>
So I take this to mean that the UILabel
with the text "Build Label" has a top constraint that is turned off. (since the viewControllerLayoutGuide
constraint should never be turned off, it must be the UILabel
.
所以我认为这意味着UILabel
带有文本“构建标签”的顶部约束已关闭。(由于viewControllerLayoutGuide
永远不应该关闭约束,它必须是UILabel
.
Lo and behold, it was not installed. I selected the Installed
checkbox for the UILabel, and the error disappeared.
瞧,它没有安装。我选中了Installed
UILabel的复选框,错误消失了。
1 down, 9 more to go! (F*ing Xcode...)
下 1 个,还有 9 个!(该死的 Xcode ......)
回答by Munahil
Show the Report Navigator
[That is the rightmost tab on the leftmost column]. This will show build log with constraint ids. For further details, look into this stackoverflow's post.
显示Report Navigator
[这是最左侧列中最右侧的选项卡]。这将显示带有约束 ID 的构建日志。有关更多详细信息,请查看此stackoverflow 的帖子。
回答by Milan Kamilya
Reason
原因
You have an item (i.e. view) which is un-Installed, but, it has constraints which are still installed.(commented by fattie)
您有一个未安装的项目(即视图),但是它具有仍然安装的约束。(胖子评论)
How to find out specific constraint
如何找出特定约束
It is difficult to find exact constraintwhich causes this warning. It mentioned step by step in BastiBen's answerhow to find out the specific constraint.
很难找到导致此警告的确切约束。它在BastiBen 的回答中逐步提到了如何找出特定约束。
Solution
解决方案
- Check both the items/views(first & second ) of the specific constraint whether any item is un-Install for any specific size-class. In my case the constraint was installed for all size-classes, but one of the item was installed for "wC hR" (Ref following image).
- Install the item to resolve the warning.
- Now, build the app, if you still find the same warning for that specific interface/XIB file, don't worry this time some other constraints have the same problem.
- 检查特定约束的项目/视图(第一和第二)是否有任何项目未安装任何特定尺寸级别。在我的情况下,为所有尺寸级别安装了约束,但为“wC hR”安装了一项(参考下图)。
- 安装该项目以解决警告。
- 现在,构建应用程序,如果您仍然发现该特定接口/XIB 文件的相同警告,这次不要担心其他一些约束也有同样的问题。
Advice for Future
对未来的建议
- Please check whether views are properly installed while copy/paste them from other interfaces.
- 从其他界面复制/粘贴视图时,请检查视图是否安装正确。
回答by Maria
You can also find the view or constraint by looking at tag in the storyboard source.
您还可以通过查看故事板源中的标签来找到视图或约束。
- Open the storyboard as source
- Look for the following tag to get the id
- Look for the id in the storyboard to find which item it is.
- 打开故事板作为源
- 查找以下标签以获取 id
- 在故事板中查找 id 以找到它是哪个项目。
回答by Ben Thomas
I had a view that I had uninstalled so the warning appeared. After reinstalling the view, the warning did not go away, even after a clean. But after restarting Xcode the warning went away.
我有一个我已经卸载的视图,所以出现了警告。重新安装视图后,警告并没有消失,即使在清洁之后也是如此。但是在重新启动 Xcode 后,警告消失了。
回答by chris
To solve this problem there are a few options:
为了解决这个问题,有几个选项:
First what causes the problem?Uninstalling a view without uninstalling it's constraints.
首先是什么导致了问题?卸载视图而不卸载它的约束。
Second why would you so this?You might want a view to remain in your view controller because you built it and then the specs changed so you wanted to remove it temporarily because perhaps that portion wasn't included in your current sprint or what have you
第二,你为什么要这样?您可能希望视图保留在您的视图控制器中,因为您构建了它,然后规范发生了变化,因此您想暂时删除它,因为也许该部分未包含在您当前的冲刺中或您有什么
Last how does one solve it?
最后一个怎么解决呢?
There are three options:
有以下三种选择:
If you can just reinstall the view
If you want to keep the view
If you can just delete the uninstalled view all together
如果你可以重新安装视图
如果你想保留视图
如果您可以一起删除已卸载的视图
Option 1
选项1
If you can just reinstall the view:
如果您可以重新安装视图:
Reinstall the view by toggling the installed option as seen in picture 2 on any view that is faded out as seen in picture 1
Try to clean the project(Command +Shift+K) - if that doesn't work, try a restart of xCode. If that doesn't work, you might have missed an uninstalled view somewhere.
通过在图 1 中淡出的任何视图上切换图 2 中所示的已安装选项来重新安装视图
尝试清理项目(Command +Shift+K) - 如果这不起作用,请尝试重新启动 xCode。如果这不起作用,您可能在某处错过了卸载的视图。
Option 2
选项 2
If you want to keep the view:
如果要保留视图:
- Find every view in your view controller system that is faded out (this means it has been uninstalled)
- 查找视图控制器系统中淡出的每个视图(这意味着它已被卸载)
- Look at the constraints associated with the view
- 查看与视图相关的约束
- Uncheck "Installed"
- 取消选中“已安装”
The constraint will now also be faded (not the constraint group) as seen in the first picture.
如第一张图片所示,约束现在也将被淡化(不是约束组)。
- Try to clean the project(Command +Shift+K) - if that doesn't work, try a restart of xCode. If that doesn't work, you might have missed a constraint somewhere.
- 尝试清理项目(Command +Shift+K) - 如果这不起作用,请尝试重新启动 xCode。如果这不起作用,您可能在某处错过了约束。
Option 3
选项 3
If you can just delete the uninstalled view all together
如果您可以一起删除已卸载的视图
Delete any views that have been uninstalled which will automatically delete their constraints
Clean the project (Command +Shift+K), if that doesn't work, try restarting xCode.
删除任何已卸载的视图,这将自动删除其约束
清理项目(Command +Shift+K),如果这不起作用,请尝试重新启动 xCode。
回答by Tycho Pandelaar
Basically, make sure that you 'uninstall' all constraints for 'uninstalled' views/buttons/etc.
基本上,确保您“卸载”“卸载”视图/按钮/等的所有约束。
回答by Suhaib
The solution was just to delete the uninstalled views. Simple as that.
解决方案只是删除已卸载的视图。就那么简单。