I want to change the frame size of a UICollectionView
in an animation that runs alongside an animated cell insertion to the same collection view inside a performBatchUpdates:completion:
block.
This is the code that triggers the cell insertion:
[collectionView performBatchUpdates:^{
indexPathOfAddedCell = ...;
[collectionView insertItemsAtIndexPaths:@[ indexPathOfAddedCell ]];
} completion:nil];
Because the cell insertion causes the collection view's contentSize
to change, I tried KVO-registering for changes to that property and then trigger the collection view frame update from the KVO handler.
The problem with that approach is that the KVO trigger for contentSize
fires too late: the cell insertion animation has already completed at that time (actually, KVO triggers right before the completion handler of performBatchUpdates:completion:
gets called but after the animation has played out in the UI).
Iʼm not using auto layout.
Edit: I put a sample project to demonstrate my problem on GitHub.
Edit 2: I should mention that I need this for a component Iʼm writing (OLEContainerScrollView
) that is supposed to be 100% independent of the collection view. Because of this, I cannot subclass the collection view layout, nor do I have influence over the code that triggers the cell animations. Ideally, a solution would also work for UITableView
, which exhibits the same behavior.