Created
December 29, 2018 05:51
-
-
Save victorchee/3b34b7b3a72a7744005d4a81384296eb to your computer and use it in GitHub Desktop.
Snow effect by emitter.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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