Explicit CALayer animation not working properly

Implicitly, things behave well. But when I try to use explicit animations to perform several animations at the same level (for example, opacity and translation), I get odd results.

First of all, I tried using CATransaction. Then I switched to CAAnimationGroup. Both don't seem to get what I want.

What do I want? All I want is to move the layer from one point to another with the initial opacity and opacity of the target. here it is!

What do I see? Here is one example ...

When a begin / commit transaction is executed, the translation appears to be correct, but the opacity is not. My beginning opacity is 0, and the target opacity is 0.5. However, when I run the animation, it mixes with 0.5, but then "binds" to 1.0 (completely opaque).

I tried to set removeOnCompletion to NO. but that didn't help either. I think the bottom line is that I need to know the difference between an AnimationGroup and a transaction.

Can someone explain this and maybe what I see regarding the strangeness of my animations?

Thanks!

+3
source share
2 answers

, . (). . , . . .

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"];
+1

.

layer.opacity=0.0f;
0

Source: https://habr.com/ru/post/1716172/


All Articles