Reputation: 53
I am currently working with UICollectionView and after changing the layout from one to another with setCollectionViewLayout:animated: I want to execute some code upon the completion of the animation. Any idea how to achieve that?
Cheers,
Upvotes: 3
Views: 871
Reputation: 4093
Just for the record, there is now a -setCollectionViewLayout:animated:completion:
method on UICollectionView
, introduced in iOS 7.
Upvotes: 4
Reputation: 172
I found that to be able to control the animation, rather than using the implicit one with setCollectionViewLayout:animated:
you can use a standard UIView animationWithDuration
and change the layout in the animations
block, like this:
[UIView animateWithDuration:0.4
delay:0
options:UIViewAnimationCurveEaseOut
animations:^{
self.oldView.collectionViewLayout = self.otherLayout;
self.newView.alpha = 1.0;
}
completion:^(BOOL finished){
self.oldView.alpha = 0.0;
self.otherLayout = nil;
}];
I don't know if it is the recommended way to do it but it lets you control the animation and execute code upon completion.
Upvotes: 3