views:

84

answers:

1

I'm trying to hide a CALayer after a few microseconds and I'm using CABasicAnimation to animate the hide.

At the moment I'm trying to use

[aLayer setHidden:YES];

CABasicAnimation * hideAnimation = [CABasicAnimation animationWithKeyPath:@"hidden"];
[hideAnimation setDuration:aDuration];
[hideAnimation setFromValue:[NSNumber numberWithBool:NO]];
[hideAnimation setToValue:[NSNumber numberWithBool:YES]];
[hideAnimation setBeginTime:0.09];
[hideAnimation setRemovedOnCompletion:NO];
[hideAnimation setDelegate:self];

[alayer addAnimation:hideAnimation forKey:@"hide"];

But when I run this, the layer is hidden immediately, rather than waiting for the desired beginTime.

I'm uncertain about my keyPath as "hidden" but couldn't find any other option and the documentation does state that the hidden property of a CALayer is animatable.

What's the correct way to achieve what I'm looking for?

+1  A: 

Try animating the opacity property instead. Go from 1.0 to 0.0 and you should get the effect you want.

Alex
If you want it to change instantly instead of fading out, you can CAKeyframeAnimation using the `kCAAnimationDiscrete` value for `calculationMode`.You should also set the `fillMode` property to `kCAFillModeBoth`.
Kevin Ballard
Thanks, I'll certainly look into it, but is there a reason why what I'm doing at the moment isn't working? Just to satisfy my curiosity :)
Tom Irving
Using opacity hasn't changed anything unfortunately. The layer is hidden / made transparent immediately, ignoring the animation completely. My delegate method for animationDidStop is also called immediately, even if my duration is something like 100 seconds (just for testing purposes).
Tom Irving