Avoid animation of UICollectionView after reloadItemsAtIndexPaths

后端 未结 9 1851
情深已故
情深已故 2020-12-04 06:07

UICollectionView animate items after reloadItemsAtIndexPaths is called (fade animation).

Is there a way to avoid this animation?

iOS 6

9条回答
  •  忘掉有多难
    2020-12-04 06:25

     func reloadRowsWithoutAnimation(at indexPaths: [IndexPath]) {
            let contentOffset = collectionView.contentOffset
            UIView.setAnimationsEnabled(false)
            collectionView.performBatchUpdates {
                collectionView.reloadItems(at: indexPaths)
            }
            UIView.setAnimationsEnabled(true)
            collectionView.setContentOffset(contentOffset, animated: false)
        }
    

提交回复
热议问题