iosswiftuicollectionviewautolayoutautosize

UICollectionView AutoSizingCells weird jump/glitch on reloadData()


I'm using UICollectionView with the AutoSizingCells feature.

Issue 1 When I use this method in conjunction with estimatedItemSize and try to call reloadData(), I can observe, how the cell's content is changed.

I.e. if I had two cells:

Cell1 - "Text1"
Cell2 - "AnotherCell"

For a second I can see this state:

Cell1 - "AnotherCell"
Cell2 - "Text1"

And then, it updates to the correct one:

Cell1 - "Updated Text"
Cell2 - "AnotherCell"

Video: ReloadData

Issue 2

When I try to reload only the selected cell, I see another bug: the whole collectionView jumps and quickly updates its size.

Video: Reload Single Item

When not using AutoSizingCells at all, there are no issues with the cell reload.

The bug is reproducible even if I don't override preferredLayoutAttributesFitting(_ layoutAttributes: UICollectionViewLayoutAttributes) -> UICollectionViewLayoutAttributes.

Is there any option to disable the animation with the AutoSizingCells enabled?


Solution

  • I had similar issues with weird jump/glitch on reloadData().

    The issue was fixed when I migrated my collection view to iOS 13 and new APIs:

    You can find sample code here: https://stackoverflow.com/a/51231881/1136128