Avoid animation of UICollectionView after reloadItemsAtIndexPaths

后端 未结 9 1847
情深已故
情深已故 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条回答
  •  猫巷女王i
    2020-12-04 06:08

    It's worth noting that if you're targeting iOS 7 and above, you can use the new UIView method performWithoutAnimation:. I suspect that under the hood this is doing much the same as the other answers here (temporarily disabling UIView animations / Core Animation actions), but the syntax is nice and clean.

    So for this question in particular...

    Objective-C:

    [UIView performWithoutAnimation:^{
        [self.collectionView reloadItemsAtIndexPaths:indexPaths];
    }];
    


    Swift:

    UIView.performWithoutAnimation {
        self.collectionView.reloadItemsAtIndexPaths(indexPaths)
    }
    


    Of course this principle can be applied for any situation that you want to ensure a change is not animated.

提交回复
热议问题