Which is the most elegant and modular way to chain animation in a Core Animation context?
I mean to do animations that starts just when other finis
Without including all the "tricks" up my "toolchain", this example isn't directly copy/pastable… but it does show a REALLY easy strategy for "chained" animations..
CATransform3D trans = m34(); // define chain-wide constants.
// Name your "stack". My "nextObject" returns arr[i]->done == nil.
NSArray *layerStack = layer.sublayers;
//define a block, that "takes" a layer as it's argument.
void(^__block ChainBlock)(CALayer*) = ^(CALayer *m) {
// animations, transforms, etc for each inividual "step".
[m animate:@"transform"
// These are just NSValue-wrapped CAT3D's
from:AZV3d(CATransform3DRotate(trans, 0,1,0,0))
to:AZV3d(CATransform3DRotate(trans,1.5,1,0,0))
time:2 // total time == each step * layerStack.count
eased:kCAMediaTimingFunctionEaseOut
completion:^{ // In completion, look for "next" layer.
CAL* m2 = [layers nextObject];
// If there is "another" layer, call this block, again... with it.
if (m2) chainAnis(m2);
// Otherise,you're done. Cleanup, toggle values, whatevs.
else self.finishedProperty = YES;
}];
};
// Give the block we just defined your "first" layer.
ChainBlock(layerStack[0]); // It will recursively feed itself.
This obviously depends on some "external magic", but the concept is simple, and eliminates (through dependencies) the need to "deal with" ANY sort of gross delegation. In particular, the animate:from:to:time:easing:completion, etc. categories come from the great FunSize Framework, on Github.