T
T
tupoi2018-06-27 14:36:53
Objective-C
tupoi, 2018-06-27 14:36:53

How to make a looped animation with a gradient?

Good afternoon, can you tell me how to make a looped animation for a gradient?
I execute the following code, as a result, the animation is played 1 time and that's it

CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
            [animationGroup setDuration:0.4];
            CABasicAnimation *firstAnimationLayer;
            CABasicAnimation *secondAnimationLayer;
            firstAnimationLayer = [CABasicAnimation animationWithKeyPath:@"startPoint"];
            firstAnimationLayer.autoreverses = YES;
            [firstAnimationLayer setRepeatCount: INFINITY];
            [firstAnimationLayer setRepeatDuration:0.3];
            [firstAnimationLayer setFromValue: [NSValue valueWithCGPoint:CGPointMake(0, 0)]];
            [firstAnimationLayer setToValue: [NSValue valueWithCGPoint:CGPointMake(0.5, 0)]];
            [firstAnimationLayer setDuration: 0.4];
            [firstAnimationLayer setBeginTime:0.0];
            
            secondAnimationLayer = [CABasicAnimation animationWithKeyPath:@"endPoint"];
            secondAnimationLayer.autoreverses = YES;
            [secondAnimationLayer setRepeatCount: INFINITY];
            [secondAnimationLayer setRepeatDuration:0.3];
            [secondAnimationLayer setFromValue: [NSValue valueWithCGPoint:CGPointMake(0.5, 0)]];
            [secondAnimationLayer setToValue: [NSValue valueWithCGPoint:CGPointMake(0.5, 1)]];
            [secondAnimationLayer setDuration: 0.4];
            [secondAnimationLayer setBeginTime:0.0];
            [animationGroup setAnimations:[NSArray arrayWithObjects:firstAnimationLayer, secondAnimationLayer, nil]];
           [self.gradient addAnimation: animationGroup forKey:nil];

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
briahas, 2018-07-05
@briahas

How about - setRepeatCount for CAAnimationGroup?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question