CAEmitterLayer是一个高性能的粒子引擎,被用来创建实时例子动画如:烟雾,火,雨等等这些效果。使用如下:
let emitter = CAEmitterLayer()
emitter.frame = self.view.bounds
self.view.layer.addSublayer(emitter)
emitter.renderMode = kCAEmitterLayerAdditive
emitter.emitterPosition = CGPointMake(emitter.frame.size.width / 2.0, emitter.frame.size.height / 2.0)
let cell = CAEmitterCell()
cell.contents = UIImage.init(named: "spark")?.CGImage
cell.birthRate = 150
cell.lifetime = 5.0
cell.color = UIColor.init(colorLiteralRed: 1, green: 0.5, blue: 0.1, alpha: 1.0).CGColor
cell.alphaSpeed = -0.4
cell.velocity = 50
cell.velocityRange = 50
cell.emissionRange = CGFloat(M_PI*2.0)
emitter.emitterCells = [cell]
效果如下:
spark.png资源: