0
我成立了一個CAEmitterLayer和它完美的作品:方法發送到CAEmitterLayer但去CALayer的
-(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'設置爲發射層嗎?我看起來像你只是鑄造。 –