我正在用CAEmitterLayer和CAEmitterCell实例创建一个粒子动画。动画没有问题,但我希望它们慢慢淡出。我使用下面的代码,但粒子突然消失,没有淡出动画。
NSString *animationPath = [NSString stringWithFormat:@"emitterCells.%@.birthRate", cell.name];
CABasicAnimation *birthRateAnimation = [CABasicAnimation animationWithKeyPath:animationPath];
birthRateAnimation.fromValue = [NSNumber numberWithFloat:30.0];
birthRateAnimation.toValue = [NSNumber numberWithFloat:0.0];
birthRateAnimation.removedOnCompletion = NO;
birthRateAnimation.duration = 10.0;
[emitterLayer addAnimation:birthRateAnimation forKey:@"birthRate"];
此代码在for循环中运行,用于五个不同的发射器单元。
你发现这段代码中的错误了吗?
谢谢
对于CAEmitterCell's设置alpha速度值为-1.0/lifetime