我设置了一个 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。当我删除那行代码时,问题仍然存在。