标签:简单的 ima make index round copy rate sha str
转自:https://segmentfault.com/a/1190000008580771
CAEmitterLayer和CAEmitterCell 主要来实现简单的例子效果:
代码如下:
- (void)setEmitter{ //添加背景图 UIImage *bgImage = [UIImage imageNamed:@"bg.jpeg"]; self.view.backgroundColor = [UIColor colorWithPatternImage:bgImage]; //粒子图层 CAEmitterLayer *snowLayer = [CAEmitterLayer layer]; snowLayer.backgroundColor = [UIColor redColor].CGColor; //发射位置 snowLayer.emitterPosition = CGPointMake(0, 100); snowLayer.emitterZPosition = -20; //发射源的尺寸 snowLayer.emitterSize = CGSizeMake(640, 1); //发射源的形状 snowLayer.emitterMode = kCAEmitterLayerSurface; //发射模式 snowLayer.emitterShape = kCAEmitterLayerLine; //存放粒子种类的数组 NSMutableArray *snow_array = @[].mutableCopy; for (NSInteger i=1; i<5; i++) { //snow CAEmitterCell *snowCell = [CAEmitterCell emitterCell]; snowCell.name = @"snow"; //产生频率 snowCell.birthRate = 15.0f; //生命周期 snowCell.lifetime = 30.0f; //运动速度 snowCell.velocity = 1.0f; //运动速度的浮动值 snowCell.velocityRange = 10; //y方向的加速度 snowCell.yAcceleration = 2; //抛洒角度的浮动值 snowCell.emissionRange = 0.5*M_PI; // snowCell.contentsScale = 0.2; //自旋转角度范围 snowCell.spinRange = 0.25*M_PI; //粒子透明度在生命周期内的改变速度 snowCell.alphaSpeed = 2.0f; //cell的内容,一般是图片 NSString *snow_str = [NSString stringWithFormat:@"snow"]; snowCell.contents = (id)[UIImage imageNamed:snow_str].CGImage; [snow_array addObject:snowCell]; } //添加到当前的layer上 snowLayer.shadowColor = [[UIColor redColor]CGColor]; snowLayer.cornerRadius = 1.0f; snowLayer.shadowOffset = CGSizeMake(1, 1); snowLayer.emitterCells = [NSArray arrayWithArray:snow_array]; [self.view.layer insertSublayer:snowLayer atIndex:0]; }
标签:简单的 ima make index round copy rate sha str
原文地址:http://www.cnblogs.com/16zj/p/7610823.html