SnapKit自动布局损坏:"无法同时满足约束条件"

时间:2016-04-08 07:05:37

标签: ios swift autolayout uicollectionviewcell snapkit

UICollectionView Cell中的两个视图。 UIImageView和UIView。像这样:layout

但是当我制定约束时,我收到一个错误:

  

无法同时满足约束

    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

为什么?

编辑:vc viewDidLoad方法中的init集合视图。 【layout.itemSize】 首次出现在ViewController错误中。但向下滚动没有错误。

    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

1 个答案:

答案 0 :(得分:1)

查看错误消息。它表示您有NSAutoResizingMaskLayoutConstraintcontentView的高度和宽度设置为0.只需禁用通过自动调整蒙版创建约束:

contentView.translatesAutoresizingMaskIntoConstraints = false