1

How to create looped animation? I'm running this code and animation is executed 1 time:

CAAnimationGroup *animationGroup = [CAAnimationGroup animation];
[animationGroup setDuration:0.4];
CABasicAnimation *firstAnimationLayer;
CABasicAnimation *secondAnimationLayer;
firstAnimationLayer = [CABasicAnimation animationWithKeyPath:@"startPoint"];
firstAnimationLayer.autoreverses = YES;
[firstAnimationLayer setRepeatCount:20];
[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:20];
[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];

I want to create animation for my gradient and looped that.

Ahmad F
  • 30,560
  • 17
  • 97
  • 143
Pavel
  • 11
  • 1

1 Answers1

0

Try this

[firstAnimationLayer setRepeatCount: INFINITY];
[secondAnimationLayer setRepeatCount: INFINITY];
SergeyBukarev
  • 1,478
  • 1
  • 12
  • 19