如何创建循环动画? 我正在运行这段代码,动画执行了1次:
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];
我想为渐变创建动画并将其循环播放。
答案 0 :(得分:0)
尝试一下
[firstAnimationLayer setRepeatCount: INFINITY];
[secondAnimationLayer setRepeatCount: INFINITY];