CALayer hide animation

I try to hide CALayerafter a few microseconds, and I use CABasicAnimationhide to animate.

I'm currently 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 hides immediately, and does not wait for the desired beginTime.

I'm not sure that my keyPath is "hidden", but could not find another option, and the documentation says that the property hiddenfor CALayeris animated.

What is the right way to achieve what I'm looking for?

+3
source share
4 answers

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

+3

CAMediaTiming.h beginTime:

, , . 0.

CACurrentMediaTime() + .

[hideAnimation setBeginTime:CACurrentMediaTime() + 0.09];
+3

, , , . - , , hidden. , opacity , ( beginTime).

(CATransition, type = kCATransitionFade), , , .

, , @Kevin --- ! --- ! , :

CAKeyframeAnimation* hiddenAnim = [CAKeyframeAnimation animationWithKeyPath:@"hidden"];
hiddenAnim.values = @[@(NO),@(YES)];
hiddenAnim.keyTimes = @[@0.0, @1.0];
hiddenAnim.calculationMode = kCAAnimationDiscrete;
hiddenAnim.duration = duration;

. , , . ( , .)

, !

+3
    CABasicAnimation *endAnimation = [CABasicAnimation animationWithKeyPath:@"opacity"];
    endAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
    [endAnimation setFromValue:[NSNumber numberWithFloat:1]];
    [endAnimation setToValue:[NSNumber numberWithFloat:0.0]];
    [endAnimation setBeginTime:AVCoreAnimationBeginTimeAtZero];
    endAnimation.duration            = 5;
    endAnimation.removedOnCompletion = NO;
    [alayer addAnimation:endAnimation forKey:nil];
0

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


All Articles