ios7 中的 UIKit 粒子系统。粒子数增加
Posted
技术标签:
【中文标题】ios7 中的 UIKit 粒子系统。粒子数增加【英文标题】:UIKit Particle Systems in ios7. Number of particles increased 【发布时间】:2013-09-12 13:36:27 【问题描述】:ios7 上的粒子系统似乎与 ios6 和 ios5 上的不同。粒子数增加。 应用程序中的所有粒子效果都会出现同样的问题。 唯一可行的解决方案是检查是否是 ios7 并降低粒子出生率。有没有更好的解决方案?
粒子发射器视图代码。
- (id)initWithFrame:(CGRect)frame
self = [super initWithFrame:frame];
if (self)
//initialize the emitter
_emitter = (CAEmitterLayer*)self.layer;
_emitter.emitterPosition = CGPointMake(self.bounds.size.width /2, self.bounds.size.height/2 );
_emitter.emitterSize = self.bounds.size;
_emitter.emitterMode = kCAEmitterLayerAdditive;
_emitter.emitterShape = kCAEmitterLayerRectangle;
return self;
- (void)didMoveToSuperview
//Check if parent is initialized
[super didMoveToSuperview];
if (self.superview==nil) return;
//Load png
UIImage* texture = self.explosionImage; //[UIImage imageNamed:@"particle.png"];
NSAssert(texture, @"particle.png not found");
//Create a new emitter cell
CAEmitterCell* emitterCell = [CAEmitterCell emitterCell];
//Set the cell’s contents property to the texture you loaded
emitterCell.contents = (__bridge id)[texture CGImage];
//Name the cell “cell”
emitterCell.name = @"cell";
//Parameters
emitterCell.birthRate = self.birthRate;// 40;//1000
emitterCell.lifetime = 2.8;
emitterCell.lifetimeRange = 0.7;
//Set the cell’s color to randomly vary its components
if (!self.explosionColor)
emitterCell.blueRange = 0.33;
emitterCell.blueSpeed = -0.33;
emitterCell.redRange = 0.33;
emitterCell.redSpeed = -0.33;
emitterCell.greenRange = 0.33;
emitterCell.greenSpeed = -0.33;
//Explosion color
if (self.explosionColor) emitterCell.color = [self.explosionColor CGColor];
//velocity
emitterCell.velocity = IS_IPAD?40:20;//160
emitterCell.velocityRange = RANDOMF(10, 20);//15
//Alpha
emitterCell.alphaSpeed = -0.73;
emitterCell.alphaRange = 0.9;
//Scale
emitterCell.scale = IS_IPAD?0.6:0.30;//0.5
emitterCell.scaleRange = 0.6;//0.5
emitterCell.scaleSpeed = 0;
//Range
emitterCell.emissionRange = M_PI*2;//2
//Add the cell to the emitter layer
_emitter.emitterCells = @[emitterCell];
[self performSelector:@selector(disableEmitterCell) withObject:nil afterDelay:self.cellIsEmitting];
[self performSelector:@selector(removeFromSuperview) withObject:nil afterDelay:self.emittingInView];
【问题讨论】:
【参考方案1】:在 iOS7 上运行时,看起来粒子系统在添加发射器层之前开始动画。 这可能是一个错误,希望将来会得到解决。
目前,要获得与 iOS6 上类似的行为,可以将 CAEmitterLayer 的 beginTime 设置为当前时间:
_emitter.beginTime = CACurrentMediaTime();
【讨论】:
以上是关于ios7 中的 UIKit 粒子系统。粒子数增加的主要内容,如果未能解决你的问题,请参考以下文章
粒子系统模块(Particle System Modules40)