How to nest multiple CA animation like UIView animateWithDuration does? For example, I need to animate 6 animations where each next animation goes after previous one. So, with UIView animateWithDuration, every next animation is called from complete block. Does CA allows to use blocks and etc.? If no then how to perform nested sequential animations?
2 Answers
CAAnimation doesn't have a block-based API, but you could use its delegate method animationDidStop:finished: to chain multiple animations.
If you do this a lot, you may want to write your own block-based wrapper for this.
2 Comments
Centurion
Not quite so tough for writing my own wrapper at this moment :) One question about using delegate: implementing animationDidStop:finished: delegate method will trigger it for all on-screen going animations (including UIView animations) or only CA animations?
omz
Only for the animations for which you set yourself as the delegate.
Alternatively to omz's answer, you can set up NSTimer objects to start the successive parts of the animation.
[NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(legOne:) userInfo:nil repeats:NO]; [NSTimer scheduledTimerWithTimeInterval:4.0 target:self selector:@selector(legTwo:) userInfo:nil repeats:NO]; Where legOne: is a method that does the first part of the animation, etc.