Repeating animation bug

Originator:an00na
Number:rdar://18126382 Date Originated:25-Aug-2014 06:12 PM
Status:Open Resolved:
Product:iOS Product Version:7 & 8
Classification:Other Bug Reproducible:Always
 
Summary:
Removing a CALayer with a endlessly repeating animation from layer tree and later adding it back ends up with odd state.

After removing the layer, the animation calls animationDidStop:finished:. It is understandable because I believe the system stops the animation when its layer is detached from the layer tree.

However, after adding the layer back to the layer tree, the animation is still going on. In one aspect, it is understandable because the animation is endlessly repeating. But, the animation does not call animationDidStart: again. So its delegate thinks it is still in stop state.

What's even worse is that [layer animationForKey:animationKey] now returns nil even though the animation is still going on. So in effect, the animation is lost because I can not get the reference to it from the layer.

The most odd thing is that the animation can still be stopped by calling [layer removeAnimationForKey:animationKey] even though [layer animationForKey:animationKey] returns nil.

As you can see, quite a lot of things are inconsistent in this state.

Steps to Reproduce:
1. Launch sample app.
2. Tap Remove button to remove the rotating view and read console log.
3. Tap Add Back button to add the rotating view back and read console log.
4. Tap Stop button to stop the rotating animation and read console log.

Expected Results:
1. CAAnimation delegate calls match the reality.
2. CALayer should always return the animation from animationForKey: if the animation is still going on.

Actual Results:
1. Animation is still going one after it calls animationDidStop:finished:.
2. [CALayer animationForKey:] returns nil even though the animation is still going on.

Sample code:
http://cl.ly/3w0q2c3U1h2X

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!