R – CALayer explicit animations not behaving properly

calayercore-animation

Implicitly things behave fine. But when i try to use explicit animations to do multiple animations on a single layer (e.g. opacity and translation) I get odd results.

First of all, i tried using CATransaction. Then i switched to CAAnimationGroup. Both doesnt seem to get what i want.

What do I want?
All i want is for a layer to move from one point to another with an initial opacity and a target opacity. thats it!

What am i seeing?
Here is one example…

When performing a transaction begin/commit, the translation appears to be correct, but the opacity is not. My start opacity is 0, and the target opacity is 0.5.
However when i run the animations, it blends to 0.5, but then "snaps" to 1.0 (fully opaque).

I tried setting the removedOnCompletion to NO. but that didnt help either.
I think the bottom line is that i need to know the difference between an AnimationGroup and a Transaction.

Can anybody explain this, and possibly what im seeing regarding the oddness of my animations?

Thanks!

Best Answer

Ok, explicit animations arent working for me. I tried creating a basic animation for opacity (of a layer). I placed this inside an animation group. When i execute, nothing happens. For simplicity i took out translation animations. This is only trying to do opacity animation.

CAAnimationGroup *group = [CAAnimationGroup animation];

CABasicAnimation *opacityAnimation;     
opacityAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];  
opacityAnimation.fromValue = [NSNumber numberWithDouble:fromalpha];     
opacityAnimation.toValue = [NSNumber numberWithDouble:toalpha];     
opacityAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
opacityAnimation.delegate = self;
opacityAnimation.duration = 2.7;        

opacityAnimation.removedOnCompletion = NO;

group.animations = [NSArray arrayWithObjects: opacityAnimation, nil];
[baseLayer addAnimation:group forKey:@"groupAnim"];
Related Topic