参考:https://ios.devdon.com/archives/1046
_snowEmitter = [CAEmitterLayer layer];
CGRect rect = CGRectMake(0.0, 0.0, windowSize.width, 40.0);
_snowEmitter.emitterPosition = CGPointMake(rect.size.width / 2, -rect.size.height / 2);
_snowEmitter.emitterSize = rect.size;
_snowEmitter.emitterMode = kCAEmitterLayerOutline;
_snowEmitter.emitterShape = kCAEmitterLayerLine;
_snowEmitter.renderMode = kCAEmitterLayerOldestLast;
CAEmitterCell *confetti = [CAEmitterCell emitterCell];
confetti.contents = (__bridge id)[[UIImage imageNamed:@"snow.png"] CGImage];
confetti.name = @"confetti";
confetti.birthRate = 5;
confetti.lifetime = 20.0;
confetti.velocity = 30;
confetti.velocityRange = 100;
confetti.emissionLongitude = (CGFloat) M_PI;
confetti.yAcceleration = 25;
confetti.alphaRange = 1.0;
confetti.alphaSpeed = -0.1;
confetti.spinRange = 10.0;
confetti.scale = 0.6;
confetti.scaleRange = 0.6;
_snowEmitter.emitterCells = [NSArray arrayWithObject:confetti];
[superLayer insertSublayer:_snowEmitter atIndex:0];
网友评论