iOS 7 CAEmitterLayer spawning particles inappropriately

五迷三道 提交于 2019-11-29 20:29:20

YES!

I spent hours on this problem myself.

To get the same kind of animation of the birthRate we had before we use a couple of strategies.

Firstly, if you want the layer to look like it begins emitting when added to the view you need to remember that CAEmitterLayer is a subclass of CALayer which conforms to the CAMediaTiming protocol. We have to set the whole emitter layer to begin at the current moment:

emitter.beginTime = CACurrentMediaTime();
[self.view.layer addSublayer:emitter];

It's as if it calculates the state the layer would be in the future.

You were eerily close, but actually its that the emitter was beginning in the past.

Secondly, to animate between a birthrate of 0 and n, with the effect that we had before we can manipulate the lifetime property instead:

if (shouldBeEmitting){
    emitter.lifetime = 1.0;
}
else{
    emitter.lifetime = 0;
}

Note that i set the lifetime on the emitter layer itself. This is because when emitting the emitter cell's version of this property gets multiplied by the value in the emitter layer. Setting the lifetime of the emitter layer sets a multiple of the lifetimes of all your emitter cells, allowing you to turn them all on and off with ease.

For me, the issue with my CAEmitterLayer, when moving to iOS7 was the following:

In iOS7 setting the CAEmitterLayerCell's duration resulted in the particle not showing at all!

The only thing I had to change was remove the cell.duration = XXX and then my particles began showing up again. I am going to eat an Apple over this unexpected, unexplained hassle.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!