I have a custom flow layout which is adjusting the attributes for cells when they are being inserted and deleted from the CollectionView with the following two functions, bu
After trying [CATransaction setAnimationDuration:]
and [UIView setAnimationDuration:]
in every possible phase of the layout process without success, I figured out a somewhat hacky way to change the duration of cell animations created by UICollectionView
that doesn't rely on private API's.
You can use CALayer
's speed
property to change the relative media timing of animations performed on a given layer. For this to work with UICollectionView
, you can change layer.speed
to something less than 1 on the cell's layer. Obviously it's not great to have the cell's layer ALWAYS have a non-unity animation speed, so one option is to dispatch an NSNotification
when preparing for cell animations, to which your cells subscribe, that will change the layer speed, and then change it back at an appropriate time after the animations are finished.
I don't recommend using this approach as a long-term solution as it's pretty roundabout, but it does work. Hopefully Apple will expose more options for UICollectionView animations in the future.
change CALayer's speed
@implementation Cell
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.layer.speed =0.2;//default speed is 1
}
return self;
}
Without subclassing:
[UIView animateWithDuration:2.0 animations:^{
[self.collection reloadSections:indexSet];
}];