1

这是我的代码——在 Xcode 6.3 for iOS8 及更高版本上编译:

//Create the emitter layer
CAEmitterLayer *emitter = [CAEmitterLayer layer];
emitter.emitterPosition = position;
emitter.emitterMode = kCAEmitterLayerOutline;
emitter.emitterShape = kCAEmitterLayerCircle;
emitter.renderMode = kCAEmitterLayerAdditive;
emitter.emitterSize = CGSizeMake(100 * multiplier, 0);

//Create the emitter cell
CAEmitterCell* particle = [CAEmitterCell emitterCell];
particle.emissionLongitude = M_PI;
particle.birthRate = multiplier * 1000.0;
particle.lifetime = multiplier;
particle.lifetimeRange = multiplier * 0.35;
particle.velocity = 180;
particle.velocityRange = 130;
particle.emissionRange = 1.1;
particle.scaleSpeed = 1.0; // was 0.3

particle.color = CGColorCreateCopy([UIColor colorWithRed:.5 green:.5 blue:.5 alpha:.5].CGColor);
UIImage *theimage = [UIImage imageNamed:@"tspark"];
particle.contents = (__bridge id)(theimage.CGImage);
particle.name = @"particle";

emitter.emitterCells = @[particle];

我一直在为发布什么而苦苦挣扎!

谢谢!

4

1 回答 1

2

创建规则”表示,如果 Core Foundation 调用名称中包含“创建”或“复制”,则必须释放它(或将所有权转移给 ARC,此处不相关)。

的文档CGColorCreateCopy也明确说明了这一点并说:

您负责使用 释放此对象CGColorRelease

所以你可以通过释放返回的对象来解决这个问题CGColorCreateCopy

CGColorRef colorRef = CGColorCreateCopy([UIColor colorWithRed:.5 green:.5 blue:.5 alpha:.5].CGColor);
particle.color = colorRef;
CGColorRelease(colorRef);

显然,更容易的是完全避免CGColorCreateCopy

particle.color = [UIColor colorWithRed:.5 green:.5 blue:.5 alpha:.5].CGColor;
于 2015-04-15T22:50:30.327 回答