Reputation: 431
I have a UICollectionView which has 12 cells. After retrieve data from network, call -reloadData of the UICollectionView and show another 12 images. My question is: is there anyway I can add an animation when the UICollectionView reloading the data, like a transition animation from the old image before reloadData to a new image after reloadData!
Any advice will be a great help!Thanks!
Upvotes: 0
Views: 2108
Reputation: 4331
Two are three ways:
The normal animations provided by collection view: [self.collectionView reloadSections:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, self.collectionView.numberOfSections)]];
(more discussion on this topic find here: SO discussion )
But you can also use the screenshot API in iOS to get some view copies at least of the currently visible ones and animated them in any way you like!
To get the currently visible cells of the collection view you can call:
[collectionView visibleCells]
For each of these you can then create a snapshot view:
UIView* singleCellSnapshot = [cell snapshotViewAfterScreenUpdates:NO];
And now animate them in any way you like!
You should create 'superview' for these animations though, where you can add the snapshots as subviews. Also make sure to translate the position coordinates of cells to the snapshots for your initial setup when you start the animation:
UIView* animationContainer = [[UIView alloc] init... ]; //probably already done in storyboard!
singleCellSnapshot.center = [cell.superview convertPoint:cell.center toView:animationContainer];
[animationContainer addSubview:singleCellSnapshot];
Upvotes: 1