Avoid animation of UICollectionView after reloadItemsAtIndexPaths

后端 未结 9 1848
情深已故
情深已故 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:27

    You could also try this:

    UICollectionView *collectionView;
    

    ...

    [UIView setAnimationsEnabled:NO];
    
    [collectionView performBatchUpdates:^{
        [collectionView reloadItemsAtIndexPaths:indexPaths];
    } completion:^(BOOL finished) {
        [UIView setAnimationsEnabled:YES];
    }];
    

    Edit:

    I have also found that if you wrap performBatchUpdates in a UIView animation block, the UIView animation is used instead of the default animation, so you can just set the animation duration to 0, like so:

    [UIView animateWithDuration:0 animations:^{
        [collectionView performBatchUpdates:^{
            [collectionView reloadItemsAtIndexPaths:indexPaths];
        } completion:nil];
    }];
    

    This is extra cool if you want to use iOS 7 springy animations during inserts and deletes!

提交回复
热议问题