views:

48

answers:

1

On the iPhone, when you add a sub layer to a visible view's layer, using either -addSublayer: or -removeFromSuperlayer, shouldn't that sub layer appear or disappear in an animated manner (ie. fade in or fade out gradually)? My program animates using layers (not views). When I change a property of a layer like position or image content, then the change does animate (layer streaks around it's parent layer, the layer fades from the old image to the new image), so I obviously have the layers & view setup correctly. However, when I add or remove a sub layer, the change occurs instantly; there is no animation.

Reading the references, it says that if the layer is visible, the sub layer should animate when adder or removed.

What am I doing wrong? Has anyone had a similar problem, and was able to find a solution?

Thank you,

Steve Sheets

+1  A: 

If you'd like a fade you can use the following CATransition:

CATransition* transition = [CATransition animation];
transition.delegate = nil;
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
transition.type = kCATransitionFade;
[theLayer addAnimation: transition forKey: nil];

Just make sure to #import <QuartzCore/QuartzCore.h> and link the framework. Call this block just before you add or remove the sublayers.

jessecurry