2
votes

Say I have 3 CALayers (squares, of different colors, for the sake of example). And I want to perform the following animation:

layer1 simultaneously translates and scales from position A to position B.

Once layer1 is in its new position and has its new size, layer2 and 3 simultaneously translate from positions C and D to positions E and F, respectively. These layers (2 and 3) also fade in as they translate to E and F. But layer2 also scales as it translates and layer3 just translates (but with a CAKeyframeAnimation so that when it reaches point F it does a little bouncy up-down effect).

  1. For layer 1, I can:

    • create a CABasicAnimation with the only setting of duration set to, say 1, and add it to layer1 for key "transform" creating a translate
    • scale transform and applying it to layer
  2. For layer2 same thing as for layer1 but also setting the opacity.

  3. For layer3 I'd create a keyframe animation. And also set the opacity.

From the above:

Seems like calling layer2 setTransform: followed by setOpacity: results in simultaneous animations. But is this the right way to make sure they are simultaneous or should I use something like CAAnimationGroup?

Does it make sense to translate and scale by concatenating matrices? Does it even make sense to use matrices as opposed to setting positions?

How do I chain these, so that the animations for layer2 and layer3 won't start until layer1 is done and then, layer2's transform and opacity happen at the same time as layer3's keyframe and opacity animations?

1

1 Answers

2
votes

I did something extremely similar today.. I was mixing CGAffineTransform and CABasicAnimations and it caused the most awkward error.. anyways.

to set animation to perform a method after completion I'm awful sure I was using:

[self performSelector:@selector(animationDone) withObject:nil afterDelay:0.0];

after I finished making 3 CABasicAnimations in one method I used, CAAnimationGroup to call all 3 at once. After the completion of the 1st animation group it would call the animationDone method to start next method of subsequent animations.

also had to be careful of the:

animationObject.fillMode = kCAFillModeForwards; //b/c of object's coordinate changes
animationObject.removedOnCompletion = NO;