views:

210

answers:

1

I'm having some problems getting CoreAnimation to perform multiple animations in succession on the iPhone simulator. I have many layers in my application that I animate – these layers are all sublayers of the layer associated with a UIView in my application. After I animate the first sublayer's position (using explicit animation - CAKeyFrameAnimation), I do the following in the animationDidStop delegate method:

  1. I remove the layer from its superlayer
  2. I start a CATransaction to animate 2 other sublayers' positions simultaneously - these layers are also animated explicitly with individual CAKeyframeAnimations added to the respective layers.
  3. I then reuse the 1st layer with different contents and add that back to the superlayer in a separate position (intentionally not animated).

When I run my application, I see the first animation occur, the layer then gets removed, and the layer gets added back with new contents in the new position, but I never see the animation of the 2 layers in step 2. Interestingly, I do get animationDidStop calls for each of the 2 layers animating in the transaction. Since I get these calls it would appear the animations are occurring, but the animations do not appear on screen. I also tried removing the transaction in case I didn't have that set up correctly and am seeing the same results.

Is it possible to link together multiple animations in this manner?

Any insights or suggestions are greatly appreciated. Thanks in advance for your help.

A: 

My first guess would be that you are adding your animation in the animationDidStop to a layer that is no longer valid. Of course, I can't know that unless you post some code.

Second, you should take a look at the timing documentation for Core Animation as the way you're doing it, while functional, may not be the best way. Specifically take a look at this section:

The timing protocol provides the means of starting an animation a certain number of seconds into its duration using two properties: beginTime and timeOffset. The beginTime specifies the number of seconds into the duration the animation should start and is scaled to the timespace of the animation's layer. The timeOffset specifies an additional offset, but is stated in the local active time. Both values are combined to determine the final starting offset.

Matt Long