CollectionView: Unable to animate ReloadItems

175 Views Asked by At

ReloadItems does not seem to allow for animation.

I tried using collectionView:( willDisplay) but the reloadItems() actually overtakes the animation (i.e. cutting it off and reloading the cell)

I tried performBatchUpdates() but I get outOfRange error in this block:

    collectionView.performBatchUpdates({
                    // reload one or more items
                    collectionView.reloadItems(at: [tappedArray[0], tappedArray[1]])
                }) { (_) in
                    // do animations here
                    if let cell1 = collectionView.cellForItem(at: self.tappedArray[1]) {
                        self.animateCell(cell1)
                    }
                }

If a single item in a collectionView is reloaded, how can I add animation(s) to the re-display of that item?

1

There are 1 best solutions below

0
Pcoder On

Issue resolution: Animation done in a closure is NOT on the main thread. Since all animation should be on the main thread, this was causing my UI to glitch, or "not allow for animation".