CAEmitterLayer*snowEmitter = [CAEmitterLayerlayer];
snowEmitter.emitterPosition=CGPointMake(self.view.bounds.size.width/2.0, -30);
snowEmitter.emitterSize=CGSizeMake(self.view.bounds.size.width*2.0,0.0);
snowEmitter.emitterMode=kCAEmitterLayerOutline;
snowEmitter.emitterShape=kCAEmitterLayerLine;
CAEmitterCell*snowflake = [CAEmitterCellemitterCell];
snowflake.scale=0.2;
snowflake.scaleRange=0.5;
snowflake.birthRate=20.0;
snowflake.lifetime=30.0;
snowflake.velocity=20;
snowflake.velocityRange=10;
snowflake.yAcceleration=2;
snowflake.emissionRange=0.5*M_PI;
snowflake.spinRange=0.25*M_PI;
snowflake.contents= (id)[[UIImageimageNamed:@"snow"]CGImage];
snowflake.color= [[UIColorcolorWithRed:0.6green:0.658blue:0.743alpha:1]CGColor];
snowEmitter.shadowOpacity=1.0;
snowEmitter.shadowRadius=0.0;
snowEmitter.shadowOffset=CGSizeMake(0.0,1.0);
snowEmitter.shadowColor= [[UIColorwhiteColor]CGColor];
snowEmitter.emitterCells= [NSArrayarrayWithObject:snowflake];
[self.view.layeraddSublayer:snowEmitter];
GitHub:使用CAEmitterLayer实现下雪和烟花效果
网友评论