我使用CABasicAnimation创建了一个脉冲动画,它工作得很好但我的问题是当我进入主屏幕或转到另一个故事板并回到应用程序或包含脉冲动画的故事板时,脉冲动画暂停,所以这是我用来制作脉冲动画的代码
CODE:
pbt.layer.transform = CATransform3DMakeScale(1.2, 1.2, 1);
CABasicAnimation *pulsy = [CABasicAnimation animationWithKeyPath:@"transform"];
pulsy.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
pulsy.autoreverses = YES;
pulsy.duration = 0.45;
pulsy.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pulsy.repeatCount = HUGE_VAL;
[pbt.layer addAnimation:pulsy forKey:@"pulseAnimation"];
答案 0 :(得分:3)
添加以下代码:
pulsy.removedOnCompletion = NO;
所以你的代码将是:
pbt.layer.transform = CATransform3DMakeScale(1.2, 1.2, 1);
CABasicAnimation *pulsy = [CABasicAnimation animationWithKeyPath:@"transform"];
pulsy.toValue = [NSValue valueWithCATransform3D:CATransform3DIdentity];
pulsy.autoreverses = YES;
pulsy.duration = 0.45;
pulsy.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
pulsy.repeatCount = HUGE_VAL;
pulsy.removedOnCompletion = NO;
[pbt.layer addAnimation:pulsy forKey:@"pulseAnimation"];