Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UICollectionView insertItem -> adjust animation time?

So, I have a UICollectionView where I insert new items.

I used the most of the suggestions from the Collection View Programming Guide - section "Making Insertion and Deletion Animations More Interesting"

Is there a way to adjust the animation time? (Maybe I just missed it in the docs, but couldn't find any info on this)

PS: If I could edit the curve that would be cool too. You know Ease-In-Out and so forth.

like image 555
Bersaelor Avatar asked Aug 15 '13 09:08

Bersaelor


3 Answers

You can change any animation speed with CALayer. So for UICollectionView this looks like the following:

[self.collectionView.viewForBaselineLayout.layer setSpeed:0.1f];

And you can change back the original speed:

[self.collectionView.viewForBaselineLayout.layer setSpeed:1.0f];

For this to work you may need to import QuartzCore:

#import <QuartzCore/QuartzCore.h>
like image 120
Adam Wallner Avatar answered Nov 15 '22 20:11

Adam Wallner


Or just do

[UIView animateWithDuration:0.5f animations:^(void) {
  [self.collectionView insertItemsAtIndexPaths:@[newIndexPath]];
}];

The animation duration will affect the internal duration of the collection view insertion animation.

like image 40
Mr Rogers Avatar answered Nov 15 '22 19:11

Mr Rogers


You cannot adjust the animation with the Apple-provided layout methods. If you want to customize the animation you need to hide the item via attributes (just show and empty space), do your animation yourself and an at the end of the animation pop the item back in via attributes.

I asked a similar question about customizing the moving animation, but the consensus has been what I described. Animate yourself if you need to.

This question shows how to do a custom removal animation, customzing insertion should be similar: UICollectionView horizontal scrolling, deleting last item, animation not working

like image 38
Cocoanetics Avatar answered Nov 15 '22 20:11

Cocoanetics