4

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!

Fran Fox
  • 575
  • 1
  • 4
  • 5

2 Answers2

3

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

Community
  • 1
  • 1
iEinstein
  • 2,100
  • 1
  • 21
  • 32
  • Thanks. Sorry, i have a reference in mi class to CAEmitterLayer instance: @property (nonatomic, strong) CAEmitterLayer *emitterLayer; I try your code but the particles continue showing :( – Fran Fox May 16 '13 at 11:06
  • Have you seen the link i have provided – iEinstein May 16 '13 at 13:22
  • Yes, but i don't understand the valid answer... I'm trying to remove from the super layer but it doesn't work :( – Fran Fox May 16 '13 at 13:46
0

I have played around with views a lot in the last months esp. with ios 5.0 to 6.0 and my experience is that you can't remove most these views with "removeFrom" but you can hide them and show then at will. Especially if your logic takes place within one view or without a root view.

You only have to implement something like this: to hide it: [YourView setHidden:YES]; or to show it: [YourView setHidden:NO];

Hope this helps,

R.

ralphb
  • 53
  • 2
  • 10