视图高度的AMBIGUOUS布局
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了视图高度的AMBIGUOUS布局相关的知识,希望对你有一定的参考价值。
我有一个UITableView
与一个单元格,其中包含:
Title label + UIStackView
带有一些按钮,下面有一个UIStackView
,带有另一个标签(描述),UICollectionView
(图像集)和一个按钮。标题标签固定在前导,尾随和顶部超视图上,底部固定在UIStackView
上(固定在标签的前端,尾部,底部和超视图的底部)。
我也在使用UITableViewAutomaticDimension
,因为UIStackView
(图片,文字)内容高度可能不同。
在我向UICollectionView
添加UIStackView
之前,一切正常,但在某些情况下添加它后布局破坏(UIStackView
内部的所有内容都重叠),在View UI Hierarchy中我可以看到警告:
*UIView:0x1038635e0- AMBIGUOUS LAYOUT for UIView:0x1038635e0.Height{id: 3153}
Legend:
* - is laid out with auto layout
+ - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
• - layout engine host
2018-01-03 10:19:58.527094+0100 Crowd Knowledge[1462:1408352] [LayoutConstraints] View has an ambiguous layout. See "Auto Layout Guide: Ambiguous Layouts" for help debugging. Displaying synopsis from invoking -[UIView _autolayoutTrace] to provide additional detail.
*Crowd_Knowledge.AttachmentsCollectionView:0x104072e00- AMBIGUOUS LAYOUT for Crowd_Knowledge.AttachmentsCollectionView:0x104072e00.minY{id: 3263}, Crowd_Knowledge.AttachmentsCollectionView:0x104072e00.Height{id: 3252}
Legend:
* - is laid out with auto layout
+ - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
• - layout engine host
2018-01-03 10:19:58.531696+0100 Crowd Knowledge[1462:1408352] [LayoutConstraints] View has an ambiguous layout. See "Auto Layout Guide: Ambiguous Layouts" for help debugging. Displaying synopsis from invoking -[UIView _autolayoutTrace] to provide additional detail.
*UIButton:0x103854dc0'Edit solution'- AMBIGUOUS LAYOUT for UIButton:0x103854dc0'Edit solution'.minY{id: 3261}, UIButton:0x103854dc0'Edit solution'.Height{id: 3258}
Legend:
* - is laid out with auto layout
+ - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
• - layout engine host
2018-01-03 10:19:59.247887+0100 Crowd Knowledge[1462:1408352] [LayoutConstraints] Window has a view with an ambiguous layout. See "Auto Layout Guide: Ambiguous Layouts" for help debugging. Displaying synopsis from invoking -[UIView _autolayoutTrace] to provide additional detail.
*UIView:0x1038635e0- AMBIGUOUS LAYOUT for UIView:0x1038635e0.Height{id: 3153}
Legend:
* - is laid out with auto layout
+ - is laid out manually, but is represented in the layout engine because translatesAutoresizingMaskIntoConstraints = YES
• - layout engine host
此外,我的UICollectionView
有一个布局,根据内容设置高度:
class DynamicCollectionView: UICollectionView {
override func layoutSubviews() {
super.layoutSubviews()
if !__CGSizeEqualToSize(bounds.size, self.intrinsicContentSize) {
self.invalidateIntrinsicContentSize()
}
}
override var intrinsicContentSize: CGSize {
return contentSize
}
}
我在故事板中没有任何警告,它在90%的时间都有效。如果它被打破,我所要做的就是滚动另一个单元格,这样它就会刷新并且约束再次起作用。我尝试了各种技巧来强制更新UI (tableView.beginUpdates() + tableView.endUpdates())
,但我仍然无法找到一个始终有效的解决方案。
我正在为这个问题寻找一个干净的解决方案。
“UIStackView(固定在superview的前导,尾随和底部)”
为什么不把它固定在超视图的顶部?你必须将它固定在superview的顶部。无需固定尺寸......
对于一个非常好的演示。见this moment of this WWDC video。我强烈建议您看整个视频。但从那一刻开始,你将学到很多关于你的问题的知识。
以上是关于视图高度的AMBIGUOUS布局的主要内容,如果未能解决你的问题,请参考以下文章
spark关于join后有重复列的问题(org.apache.spark.sql.AnalysisException: Reference '*' is ambiguous)(代码片段