PinLayout icon indicating copy to clipboard operation
PinLayout copied to clipboard

invalid parameter not satisfying: !cgsizeequaltosize(size, cgsizezero)

Open wjling opened this issue 3 years ago • 7 comments

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.

wjling avatar Feb 24 '22 03:02 wjling

Can you reproduce the issue in a sample project and post it here? It would be a lot easier to troubleshoot.

antoinelamy avatar Feb 24 '22 04:02 antoinelamy

@antoinelamy I make a demo and you can check it. I write some comments in code to describe the situations TestPinLayout.zip

wjling avatar Feb 28 '22 08:02 wjling

image I don't know if it is right, but it runs without exception.

protosse avatar Mar 09 '22 05:03 protosse

image

@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.

wjling avatar Mar 09 '22 07:03 wjling

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?

lucdion avatar Mar 09 '22 13:03 lucdion

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.

jsyrtsov avatar Mar 09 '22 15:03 jsyrtsov

image

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?

wjling avatar Mar 10 '22 03:03 wjling