在iOS 9中,当出生率超过5时CAEmitterlayer崩溃

时间:2015-09-29 04:29:33

标签: objective-c xcode ipad ios9 caemitterlayer

我在iPad项目中使用粒子发射器(不使用SpriteKit),粒子发射器是在UIImageView内部生成的,自iOS 9以来,这个发射器正在使整个应用程序崩溃。实际上,整个iPad都崩溃了,图像冻结了,没有任何东西可以让iPad在重新启动iPad时解冻。

如果我将出生率从19.0f降到6.0f,iPad就会停止崩溃。 我正在使用的图像是一个256×256大小的png,我不确定它是否会在崩溃中发挥作用。

在iOS 8中一切正常。

我目前使用Xcode 7.0.1在iPad Air 2上使用iOS 9.0.1。

+(void)smogGeneral:(UIImageView *)myView{
    [myView setNeedsDisplay];
    CALayer *rootLayer = [myView layer];
    CALayer *emitterSuperLayer = [CALayer layer];
    emitterSuperLayer.bounds = myView.bounds;
    emitterSuperLayer.sublayerTransform = CATransform3DMakeScale(1.0f, -1.0f, 1.0f);
    [rootLayer addSublayer:emitterSuperLayer];
    CGFloat midX = floorf(CGRectGetMidX(myView.bounds));
    CGFloat midY = floorf(CGRectGetMidY(myView.bounds));
    [emitterSuperLayer setPosition:CGPointMake(midX, midY)];

    CAEmitterLayer *whiteSmokeEmitter = [CAEmitterLayer layer];
    [whiteSmokeEmitter setName:@"whiteSmokeEmitter"];
    whiteSmokeEmitter.zPosition = 0.00f;
    whiteSmokeEmitter.emitterPosition = CGPointMake(300, 300);
    whiteSmokeEmitter.renderMode = kCAEmitterLayerBackToFront;
    whiteSmokeEmitter.emitterSize = CGSizeMake(10.00f, 10.0f);
    whiteSmokeEmitter.velocity = 0.05f;
    whiteSmokeEmitter.emitterMode = kCAEmitterLayerOutline;
    whiteSmokeEmitter.emitterShape = kCAEmitterLayerRectangle;

    CAEmitterCell *puffCell = [CAEmitterCell emitterCell];
    [puffCell setName:@"puffCell"];
    puffCell.contents = (__bridge id)[[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"smokeCell" ofType:@"png"]] CGImage];;
    CGColorRef colorRefPuffcell = [UIColor colorWithRed:0.99f green:0.98f blue:1.00f alpha:0.10f].CGColor;
    puffCell.color = colorRefPuffcell;
    puffCell.scale = 0.2f;
    puffCell.emissionLongitude = 1.84f;
    puffCell.emissionRange = 1.11f;
    puffCell.lifetime = 16.0f;
    puffCell.birthRate = 19.0f;
    puffCell.scaleSpeed = 0.15f;
    puffCell.velocity = 2.56f;
    puffCell.velocityRange = 9.80f;
    puffCell.xAcceleration = 9.15f;
    puffCell.yAcceleration = -0.01f;

    whiteSmokeEmitter.emitterCells = @[puffCell];
    [emitterSuperLayer addSublayer:whiteSmokeEmitter];
}

0 个答案:

没有答案