PinLayout
PinLayout copied to clipboard
invalid parameter not satisfying: !cgsizeequaltosize(size, cgsizezero)
I use UICollectionViewCompositionalLayout
to layout my collectionView. I have a custom cell A and a custom view B. Cell A's contentView adds B as a subview. Both cell A and view B has autoSizeThatFits
in method sizeThatFits
. But I get an exception when I enter the viewController said invalid parameter not satisfying: !cgsizeequaltosize(size, cgsizezero)
. If I remove autoSizeThatFits
code and it runs without exception. I can't figure out where is wrong.
Can you reproduce the issue in a sample project and post it here? It would be a lot easier to troubleshoot.
@antoinelamy I make a demo and you can check it. I write some comments in code to describe the situations TestPinLayout.zip


@protosse I crashes like this. I'm using Xcode 13.2.1, simulator iOS 15.2. You mean I should use contentView.autoSizeThatFits(size, layoutClosure: layoutMyViews)
, not autoSizeThatFits(size, layoutClosure: layoutMyViews)
? I test your code and it runs without crash, but it seems the layout isn't right. To show the right layout you can use both code 1.
I've found this answer: https://stackoverflow.com/a/64767502/4342765
It was just because I forgot to set translatesAutoresizingMaskIntoConstraints to false for a subview I was adding to cell's contentView...
Could it be this?
You can't call autosizethatfits in UICollectionViewCell. I got the same errors while calling it so. I found another solution to create autosizing cells in collection view.

No luck. Still crashes
I've found this answer: https://stackoverflow.com/a/64767502/4342765
It was just because I forgot to set translatesAutoresizingMaskIntoConstraints to false for a subview I was adding to cell's contentView...
Could it be this?