ios7中的UIKit粒子系统。颗粒数量增加

时间:2013-09-12 13:36:27

标签: ios objective-c uikit ios7 particle-system

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 个答案:

答案 0 :(得分:2)

在iOS7上运行时,看起来粒子系统开始动画的时间早于添加发射器层的时间。 这可能是一个错误,希望将来能够解决。

目前,要获得与iOS6类似的行为,CAEmitterLayer的beginTime可以设置为当前时间:

_emitter.beginTime = CACurrentMediaTime();