重新加载 Collection 没有动画的视图 Swift

Reload Collection View without animation Swift

如何在没有动画的情况下只重新加载一个单元格。我尝试使用

horizontalItem.selectedType = horizontalItem.selectedType == .deselected ? .selected : .deselected
collectionView.reloadItems(at: [indexPath])

并更改背景和标题颜色,但会更改动画。

您可以使用UIView

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