How to disable UICollectionView self sizing cells animation

I'm working with UICollectionView and self-sizing cells using a cell with Auto-Layout and setting estimatedItemSize.


The problem I'm running into is that the UICollectionView appears to be animating the difference between what the cell's actual size is and what the estimatedItemSize was. This is really not useful and I'm trying to figure out how to stop it.

In my cellForItematIndexPath method I do the cell configuration and run a layout with layoutIfNeeded. I've tried wrapping all of this with CATransaction/kCATransactionDisableActions, UIView/performWithoutAnimation and UIView/animateWithDuration:0, all with no effect.


I *can* disable animations on batch updates by wrapping the UICollectionView's performBatchUpdates with a UIView/animateWithDuration:0 but this doesn't prevent the cell by cell animation as the user scrolls through the collectionView.


Does anybody have an idea if my suspicion is correct and what I can do about it?

Using Xcode 8.2.1 and testing on iOS 10.2


Thanks!

After doing some more reading and thinking about it - it could be this is happening in the UICollectionViewFlowLayout I'm using.

So, maybe the question is: how can I make UICollectionViewFlowLayout not animate the difference between estimatedItemSize and actual size?

Accepted Answer

I realized that the root of my problem was using performBatchUpdates at all. The whole purpose of that method is to animate changes to the collection view.


The reason I went down that path was to have a completion hook to know when the collection view had finished updating so I could then safely scroll the view programmatically. I found another way of doing that and was able to just do reloadData instead which does not perform any animation.

I'm having the same problem, but calling reloadData is a non-starter. I *want* the animations.


In my mind, it is a bug that UICollectionView *ever* uses the estimatedItemSize to actually set the frame of the cells. It should *only* be used when a cell is offscreen to provide an approximate calculation for the thumb size. The fact that cells are sized *on screen* to their estimated size instead of their actual preferred size is a pretty bad bug, IMO.

How to disable UICollectionView self sizing cells animation
 
 
Q