0

Two view in UICollectionView Cell. UIImageView and 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. 【layout.itemSize 】 when first in ViewController error. 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
  • I believe it's because you're setting the top of descView to the bottom of imgView, yet still requiring descView to have a height of 44 and remain fixed to the bottom of the contentView. That's one constraint too many. – sdasdadas Oct 06 '16 at 15:30

1 Answers1

1

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:

contentView.translatesAutoresizingMaskIntoConstraints = false

Michał Ciuba
  • 7,876
  • 2
  • 33
  • 59
  • Thank you for your answer。 but i set `contentView.translatesAutoresizingMaskIntoConstraints `. The result of the bad . ImageView width and height not constraint。 i found that if i give a number to imageview height . it works fine. but if autolayout bottom to UIView top. not work – Jinghui Zhang Apr 08 '16 at 10:54
  • This helped me out... though instead of manually setting .translatesAutoresizingMaskIntoConstraints to false (which got rid of the error but messed up my cell layout) I ended up setting snap kit constraints on my contentView and that got rid of my error and my layout still looked good. Thanks! – CodenameDuchess Aug 23 '17 at 15:27