UICollectionViewLayout iOS12

Hi,

I'm updating my app for iOS12. I'm using a collectionView with a custom UICollectionViewLayout with Xcode 10 GM. All Swift code has been converted to Swift 4.2. The app runs fine under iOS 11 but under iOS 12 the layout is completely wrong. It's an issue similar to what is described here. But adding calls to invalidateLayout() all over the place hasn't made a difference.


Anybody have any ideas what to do?

Have you defined constraints in the CollectionCell ? What are they ?


Can you also show the code where you build the collectionView ?

Yes, my cell has constraints which are defined in IB. Your questions made me review all of the constraints. I had two constraints which were not being used (installed was not checked and they had not references). I deleted them and now my collectionview layout is fine in both iOS 11 and 12. For what it's worth, I've been using UICollectionView with custom UICollectionViewLayout since iOS 9 without any issues; no layout warnings during execution or anything.


I even removed all the calls to invalidateLayout() I had sprinkled around so it does appear to be related to those unused constraints.


As a final test I added back the un-used constraints and the layout went back to its original incorrect state.


So, it would be great to know whay this happened but at this point, I've got other iOS 12 things to do.


I guess my lesson learned is to keep my layout as clean as possible.

Accepted Answer

Great. Sure, it is better to keep layout as clean and as simple as possible.


Another thing I do when I have issues with layout is to give them and identifier (as thisView#01, thisView#02…) so that I can track more easily when there is an error.


Don't forget to close the thread.

I am facing the same issue,
I added 4 different types of collection view cell nib with fix width and dynamic height

all constrain updated when I scroll collectionview

UICollectionViewLayout iOS12
 
 
Q