The animation glitch is seen where the contentSize
of the collection view shrinks such that its height or width becomes smaller than (or equal to) that of the collection view bounds.
It's possible to force the expected animation in the batch update block using setContentOffset:animated:
and similar, but this relies on knowing the projected content size after deletion. Content size is managed by the collection view layout, but since we haven't actually deleted the cell yet, we can't just ask the layout (or we'd get the old size).
To work around this I implemented the targetContentOffsetForProposedContentOffset:
method in my custom layout to adjust the content offset as desired. The code below, which only accounts for Y offset, was sufficient for my needs:
- (CGPoint)targetContentOffsetForProposedContentOffset:(CGPoint)proposedContentOffset
{
if (self.collectionViewContentSize.height <= self.collectionView.bounds.size.height)
{
return CGPointMake(proposedContentOffset.x,0);
}
return proposedContentOffset;
}
I tried this out in a direct UICollectionViewFlowLayout subclass and it does the job there too.