先来看看效果图:

下面直接上代码:
粒子特效的话我只服苹果系统的,CAEmitter粒子特效提供了非常丰富的属性来实现各种效果(雨滴、雪花、流星),用法简单B格高。首先创建好CAEmitterLayer粒子发射器图层,CAEmitterCell粒子单元,然后根据需要设置somany粒子单元的属性就OK了,最后注意要将粒子发射器图层的layer添加到整个背景的sublayer上。
@interface XMWeatherView () @property(nonatomic,strong) CAEmitterLayer *sunshineEmitterLayer; @property(nonatomic,strong) CAEmitterLayer *rainDropEmitterLayer; @property(nonatomic,strong) UIImageView *backgroundView; @end
每个属性都有详细注释,最后就发挥您的想象力,爱怎么玩怎么玩吧!
#pragma mark - 下雨特效
-(void)addRainningEffect{
  self.backgroundView.image=[UIImage imageNamed:@"rainning.jpeg"];
  //粒子发射器图层
  self.rainDropEmitterLayer=[CAEmitterLayer layer];
  //粒子发射器位置
  _rainDropEmitterLayer.emitterPosition=CGPointMake(100, -30);
  //粒子发射器的范围
  _rainDropEmitterLayer.emitterSize=CGSizeMake(self.bounds.size.width*4, 0);
  //发射模式
  _rainDropEmitterLayer.emitterMode=kCAEmitterLayerOutline;
  //粒子模式
  _rainDropEmitterLayer.emitterShape=kCAEmitterLayerLine;
  //创建粒子
  CAEmitterCell *emitterCell=[CAEmitterCell emitterCell];
  //设置粒子内容
  emitterCell.contents=(__bridge id)([UIImage imageNamed:@"42-Raindrop"].CGImage);
  //设置粒子缩放比例
  emitterCell.scale=0.9;
  //缩放范围
  emitterCell.scaleRange=0.5;
  //每秒粒子产生数量
  emitterCell.birthRate=130;
  //粒子生命周期
  emitterCell.lifetime=5;
  //粒子透明速度
  emitterCell.alphaSpeed=-0.1;
  //粒子速度
  emitterCell.velocity=280;
  emitterCell.velocityRange=100;
  //设置发射角度
  emitterCell.emissionLongitude=-M_PI;
//  emitterCell.emissionRange=M_PI;
  //设置粒子旋转角速度
//  emitterCell.spin=M_PI_4;
  //设置layer阴影
  _rainDropEmitterLayer.shadowOpacity=1.0;
  //设置圆角
  _rainDropEmitterLayer.shadowRadius=2;
  //设置偏移
  _rainDropEmitterLayer.shadowOffset=CGSizeMake(1, 1);
  //设置颜色
  _rainDropEmitterLayer.shadowColor=[UIColor whiteColor].CGColor
  ;
  //设置layer的粒子
  _rainDropEmitterLayer.emitterCells=@[emitterCell];
  _rainDropEmitterLayer.transform=CATransform3DMakeRotation(-M_PI/4, 0, 0, 1);
  [self.layer addSublayer:_rainDropEmitterLayer];
}
樱花的代码大同小异,请自行脑补。
这一篇就到这里了,大家有什么意见和问题记得及时反馈哦,希望本文对大家开发iOS有所帮助。