Skip to content

Instantly share code, notes, and snippets.

@victorchee
Created December 29, 2018 05:51
Show Gist options
  • Save victorchee/3b34b7b3a72a7744005d4a81384296eb to your computer and use it in GitHub Desktop.
Save victorchee/3b34b7b3a72a7744005d4a81384296eb to your computer and use it in GitHub Desktop.
Snow effect by emitter.
let emitterLayer = CAEmitterLayer()
emitterLayer.frame = navigationView.bounds
emitterLayer.renderMode = .oldestLast
emitterLayer.emitterShape = .rectangle
emitterLayer.emitterSize = CGSize(width: navigationView.bounds.width, height: navigationView.bounds.height / 2)
emitterLayer.emitterPosition = CGPoint(x: navigationView.bounds.width / 2, y: 0)
navigationView.layer.insertSublayer(emitterLayer, at: 0)
let emitterCell = CAEmitterCell()
emitterCell.contents = UIImage(named: "triangle1")?.cgImage
emitterCell.birthRate = 2
emitterCell.lifetime = 5
emitterCell.lifetimeRange = 1
emitterCell.alphaSpeed = 5
emitterCell.alphaRange = 1
emitterCell.velocity = 50
emitterCell.velocityRange = 10
emitterCell.emissionLongitude = CGFloat.pi / 2
emitterCell.emissionLatitude = CGFloat.pi / 2
emitterCell.emissionRange = CGFloat.pi / 4
emitterCell.spin = 0.5
emitterCell.xAcceleration = 10
emitterCell.yAcceleration = 30
emitterCell.scale = 0.5
emitterCell.scaleSpeed = -0.15
emitterCell.scaleRange = 0.1
emitterLayer.emitterCells = [emitterCell]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment