3

I have the following code that adds particles to a UIView named ParentView at the center of some other UIView:

CAEmitterLayer *emitterLayer = [CAEmitterLayer layer];
emitterLayer.emitterPosition = CGPointMake(view.center.x, view.center.y - view.frame.size.height / 3);
emitterLayer.emitterZPosition = 10;
emitterLayer.emitterSize = CGSizeMake(view.bounds.size.width, 0);
emitterLayer.emitterShape = kCAEmitterLayerSphere;

CAEmitterCell *emitterCell = [CAEmitterCell emitterCell];
emitterCell.scale = 0.1;
emitterCell.scaleRange = 0.2;
emitterCell.emissionRange = 45;
emitterCell.lifetime = 0.75;
emitterCell.birthRate = 60;
emitterCell.velocity = 200;
emitterCell.velocityRange = 50;
emitterCell.yAcceleration = 250;
emitterCell.contents = (id)[[UIImage imageNamed:@"particle.png"] CGImage];

emitterLayer.emitterCells = [NSArray arrayWithObject:emitterCell];
[parentView.layer addSublayer:emitterLayer];

Everything works well but now I want to pause or suspend the animation, so the particles "freeze". Can this be done?

Hahnemann
  • 4,378
  • 6
  • 40
  • 64

1 Answers1

1

I think pause the layer will work,

-(void)pauseLayer:(CALayer*)layer
{
    CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
    layer.speed = 0.0;
    layer.timeOffset = pausedTime;
}