Search code examples
iosobjective-cparticle-systemcaemitterlayer

How to remove an CAEmitterLayer?


I'm playing with particle system in iOS using CAEmitterLayer (like in this example) but i can't remove the particles when i want.

I'm trying the following code but it doesn't work:

[self.emitterLayer setLifetime:0];
[self.emitterLayer removeFromSuperlayer];
[self.setEmitterLayer:nil];

Any suggestions? Thanks!


Solution

  • Please use this

    for (CALayer *layer in _plusButton.layer.sublayers) {
        if (layer.class == [CAEmitterLayer class]) {
            [layer removeFromSuperlayer];
        }
    
    }
    

    and please find the link that is helpful for you here