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];
}