[IOS] to solve the problem of overlapping views caused by using reloadeitems atindexpaths to update local cells in uicollectionview

Time:2020-8-27

Uicollectionview is similar to uitableview in that reloaddata can be used to update cell content.

Uicollectionview can take the reloadeitemsintdexpaths method.

self.collectionView.reloadItems(at: [indexPath])

The passed in parameter is an array composed of the indexpath of the cell to be refreshed.

However, reloadeitems atindexpath has an animation process by default, and the moment the cell content is updated, the original content will overlap with the new content. Then use the following method to cancel the animation:

UIView.performWithoutAnimation {
     self.collectionView.reloadItems(at: [indexPath])
}

If you use reloaddata to update all cells, there is no default animation process.