Reputation: 1878
I want to reload collection with animation. I gone through documentation, they have provided below method. I used it. It is working fine. Now I want to handle speed of animation (slow/fast). Is it possible through this method?
- (void)performBatchUpdates:(void (^)(void))updates completion:(void (^)(BOOL finished))completion;
My code:
[mycollectionView performBatchUpdates:^{
[mycollectionView reloadData];
};
Upvotes: 2
Views: 5758
Reputation: 2842
Whew. I'm a bit late, but if you're caching the contents of your cell, you can just animate the items that aren't cached yet and let the cached cells display as is. That way you aren't repeating cell animation for the cells that are reused.
Upvotes: 0
Reputation: 19
to add moving effect and animation to cells :
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
CGFloat xx=cell.frame.origin.x;
CGFloat yy=cell.frame.origin.y;
CGRect frame = cell.frame;
frame.origin.x = 500; // new x coordinate
frame.origin.y = 0; // new y coordinate
cell.frame = frame;
[UIView animateWithDuration:2.0 animations:^{
CGRect frame = cell.frame;
frame.origin.x = xx; // new x coordinate
frame.origin.y = yy; // new y coordinate
cell.frame = frame;
// cell.entityImageEffect.alpha = 1;
}];
return cell;
}
Upvotes: 2
Reputation: 7332
I'm not sure, but I don't think it is really possible to do via simply calling performBatchUpdates:
, I don't think It makes sense overriding it.
But simple trick to do this is to make a cell transparent, and then call a UIView's animateWithDuration:animations:
in collectionView:cellForItemAtIndexPath:
For example:
- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"SMSourceEntityCell";
SMSourceEntityCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:CellIdentifier forIndexPath:indexPath];
cell.backgroundImageView.alpha = 0.1;
cell.entityImageView.alpha = 0.1;
cell.entityImageEffect.alpha = 0.1;
[UIView animateWithDuration:2.0 animations:^{
cell.backgroundImageView.alpha = 1;
cell.entityImageView.alpha = 1;
cell.entityImageEffect.alpha = 1;
}];
return cell;
}
Upvotes: 1