Understanding UICollectionViewLayout

I’ve been struggling to understand UICollectionViewLayout.

Specifically, I want to create layouts that handle self-sizing cells, seamless rotation animations, insertion/deletion animations, etc.

Whilst the examples and sample code provided at https://developer.apple.com/documentation/uikit/views_and_controls/collection_views/layouts/customizing_collection_view_layouts are a good start they omit key functionality for more involved layouts – namely the combination of self-sizing and rotation, insertion/deletion animations.

I’ve spent quite a bit of time now trying to understand how to create a layout that both self-sizes cells and supports rotation animations. I’ve discovered quite a few things that are undocumented with a collection view layout; for example, that a multi-pass layout phase commences and initialLayoutAttributes needs to match the last value returned by layoutAttributesForElements(in:) or layoutAttributesForItem(at:) to ensure a seamless cell animation.

But other things elude me, like how to ensure initialLayoutAttributesForAppearingItem(at:) is called for all the cells it should be. Without the expected call during a rotation transition a cell may appear at its final dimensions rather than animating smoothly from the dimensions that would be appropriate for the old bounds.

In an attempt to understand the behaviour of a UICollectionViewLayout more deeply, I've sub-classed Apple’s own compositional and flow layouts to when the public methods of UICollectionViewLayout are called and what they return. But it seems that most of UICollectionViewLayout's public methods aren’t called (only layoutAttributesForElements(in:)) which makes it really tough to try and understand and replicate the desired behaviour.

Are there any more resources to *really* understand how this key component works so that we as developers can create the same calibre of seamless transitions and layouts that Apple can?

(Documentation enhancement request FB8608656)