步骤
1.创建发射器(CAEmitterLayer)
2.设置粒子属性
代码
//创建发射器
let emitterLayer = CAEmitterLayer();
//设置发射器位置
emitterLayer.emitterPosition = CGPoint(x: Screen_Width/2, y: Screen_Height )
//开启三位效果
emitterLayer.preservesDepth = true
//创建粒子,并设置属性
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
//每秒弹出的个数
cell.birthRate = 10
//展示的图片
cell.contents = UIImage(named: "good5_30x30_")?.cgImage
//旋转
cell.spin = CGFloat.pi/2/4
cell.spinRange = CGFloat.pi/2/6
emitterLayer.emitterCells = [cell]
view.layer.addSublayer(emitterLayer)