3
votes

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!

2
You should be able to animate these properties implicitly by setting the alpha value and position property of the layer. Sounds like you're on the right track. Stack them together in a CATransaction begin/commit and they will animate atomically. Post your code if that's not working properly.Joe Ricioppo
Implicit animations work, but id like to create them explicitly do i can handle the completed event when an animation completes itself.AlvinfromDiaspar

2 Answers

1
votes

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"];
0
votes

You have to set the layers opacity to the value after the animation in explicit animations.

layer.opacity=0.0f;