【发布时间】:2013-08-18 13:45:52
【问题描述】:
我设置了一个 CAEmitterLayer,它运行良好:
-(void)awakeFromNib
{
//set ref to the layer
emitter = (CAEmitterLayer*)self.layer;
emitter.emitterPosition = CGPointMake(160, 270);
CAEmitterCell* grassLeft = [self getEmitter];
CAEmitterCell* grassRight = [self getEmitter];
grassLeft.emissionLongitude = M_PI*1.20;
grassRight.emissionLongitude = M_PI*1.80;
//add the cell to the layer and we're done
emitter.emitterCells = [NSArray arrayWithObjects:grassLeft,grassRight,nil];
}
但是我加了一行代码:
-(void)awakeFromNib {
//set ref to the layer
emitter = (CAEmitterLayer*)self.layer;
emitter.emitterPosition = CGPointMake(160, 270);
emitter.backgroundColor = [[UIColor redColor] CGColor];
CAEmitterCell* grassLeft = [self getEmitter];
CAEmitterCell* grassRight = [self getEmitter];
grassLeft.emissionLongitude = M_PI*1.20;
grassRight.emissionLongitude = M_PI*1.80;
//add the cell to the layer and we're done
emitter.emitterCells = [NSArray arrayWithObjects:grassLeft,grassRight,nil];
}
突然间,我收到了Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[CALayer setEmitterPosition:]: unrecognized selector sent to instance 0x7546390'。调试窗口显示该对象是 CAEmitterLayer,而不仅仅是 CALayer。而当我删除那行代码时,问题依然存在。
【问题讨论】:
-
你真的把
self.layer设置成发射层了吗?我看起来你只是在投射。
标签: iphone objective-c calayer caemitterlayer