先來看看後果圖:

上面直接上代碼:
粒子殊效的話我只服蘋果體系的,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有所贊助。
【iOS動畫完成雨花與櫻花殊效】的相關資料介紹到這裡,希望對您有所幫助! 提示:不會對讀者因本文所帶來的任何損失負責。如果您支持就請把本站添加至收藏夾哦!