视图高度的AMBIGUOUS布局

时间:2018-01-03 09:55:15

标签: ios swift uitableview uicollectionview autolayout

我有一个UITableView,其中的单元格包含:

Title label + UIStackView带有一些按钮,下面是UIStackView,带有另一个标签(描述),UICollectionView(图像集)和一个按钮。标题标签固定在前导,尾随和顶部超视图上,底部固定在UIStackView(固定在标签的前端,尾部,底部和超视图的底部)。

enter image description here

我还使用了UITableViewAutomaticDimension,因为UIStackView内的内容高度可能不同(图片,文字)。

在我向UICollectionView添加UIStackView之前,一切正常,但在某些情况下添加布局后(UIStackView内的所有内容都重叠)并在视图中UI层次结构我可以看到警告:

enter image description here

*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%的时间都有效。如果它被打破,我所要做的就是滚动另一个单元格,以便它刷新并且约束再次起作用。我已经尝试过各种技巧来强制更新用户界面(tableView.beginUpdates() + tableView.endUpdates()),但我仍然无法找到始终有效的解决方案。

我正在为这个问题寻找一个干净的解决方案。

1 个答案:

答案 0 :(得分:0)

" UIStackView(固定在superview的前导,尾随和底部)"

为什么它没有固定在超级视图的顶部?你必须将它固定在superview的顶部。不需要固定尺寸......

非常好的演示。见this moment of this WWDC video。我强烈建议您看整个视频。但从那一刻开始,你将对你的问题有很多了解。