简体   繁体   English

SnapKit自动布局中断:“无法同时满足约束条件”

[英]SnapKit autolayout broken: “Unable to simultaneously satisfy constraints”

Two view in UICollectionView Cell. UICollectionView Cell中的两个视图。 UIImageView and UIView . UIImageView和UIView。 Like this: layout 像这样: 布局

But when I make constraints, I get an error: 但是当我进行约束时,会出现错误:

Unable to simultaneously satisfy constraints 无法同时满足约束

    imgView.snp_makeConstraints { make in
        make.top.equalTo(contentView)//.inset(K.Space.Small)
        //make.bottom.equalTo(self.descView.snp_top)//.inset(K.Space.Small.negative())
        make.left.right.equalTo(contentView)
    }

    descView.snp_makeConstraints { make in
        make.bottom.equalTo(contentView)
        make.left.right.bottom.equalTo(contentView)
        make.height.equalTo(44)
        make.top.equalTo(imgView.snp_bottom)
    }

Error: error 错误: 错误

Why? 为什么?

edit: init collection view in vc viewDidLoad method. 编辑:vc viewDidLoad方法中的init集合视图。 【layout.itemSize 】 when first in ViewController error. 【layout.itemSize】在ViewController中首次出现错误。 but scroll down no error. 但向下滚动没有错误。

    let collectionContentInset = UIEdgeInsets(top: 0, left: 12, bottom: 0, right: 12)
    var collectionItemSize = DXLayoutSize(aspectRatio: 1.35)
    collectionItemSize.containerInset = collectionContentInset

    let layout = UICollectionViewFlowLayout()
    layout.itemSize = collectionItemSize.itemSize()
    layout.minimumInteritemSpacing = 6;
    layout.minimumLineSpacing = 0;

    collectionView = UICollectionView(frame: CGRectZero, collectionViewLayout: layout)
    collectionView!.backgroundColor = DXUIColor.Background.color()
    collectionView!.showsHorizontalScrollIndicator = false

    collectionView!.contentInset = collectionContentInset

Look at the error message. 查看错误消息。 It says that you have a NSAutoResizingMaskLayoutConstraint which sets contentView 's height and width to 0. Just disable creating constraints from autoresizing masks: 它说您有一个NSAutoResizingMaskLayoutConstraint ,它将contentView的高度和宽度设置为0。只需禁用通过自动调整大小的遮罩创建约束:

contentView.translatesAutoresizingMaskIntoConstraints = false

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM