步驟
1.創(chuàng)建發(fā)射器(CAEmitterLayer)
2.設(shè)置粒子屬性
代碼
//創(chuàng)建發(fā)射器
let emitterLayer = CAEmitterLayer();
//設(shè)置發(fā)射器位置
emitterLayer.emitterPosition = CGPoint(x: Screen_Width/2, y: Screen_Height )
//開啟三位效果
emitterLayer.preservesDepth = true
//創(chuàng)建粒子,并設(shè)置屬性
let cell = CAEmitterCell()
//粒子速度
cell.velocity = 150
cell.velocityRange = 100
//粒子大小
cell.scale = 0.7
cell.scaleRange = 0.3
//粒子方向
cell.emissionLongitude = -CGFloat.pi/2
cell.emissionRange = -CGFloat.pi/2/6
//存活時間
cell.lifetime = 3
cell.lifetimeRange = 1.5
//每秒彈出的個數(shù)
cell.birthRate = 10
//展示的圖片
cell.contents = UIImage(named: "good5_30x30_")?.cgImage
//旋轉(zhuǎn)
cell.spin = CGFloat.pi/2/4
cell.spinRange = CGFloat.pi/2/6
emitterLayer.emitterCells = [cell]
view.layer.addSublayer(emitterLayer)