Skip to content

Instantly share code, notes, and snippets.

@Coder-ACJHP
Created April 15, 2019 08:01
Show Gist options
  • Save Coder-ACJHP/0b73d776d2b748ad9ed625c71ae0bdeb to your computer and use it in GitHub Desktop.
Save Coder-ACJHP/0b73d776d2b748ad9ed625c71ae0bdeb to your computer and use it in GitHub Desktop.
//
// EmitterProvider.swift
//
// Created by Coder ACJHP on 15.04.2019.
// Copyright © 2019 FitBest Bilgi Teknolojileri. All rights reserved.
//
import UIKit
class EmitterProvider {
static func createEmitterLayer(onView: UIView, withShape: UIImage) {
let layer = CAEmitterLayer()
layer.emitterShape = .line
layer.emitterCells = getCellList(withShape: withShape)
layer.position = CGPoint(x: onView.frame.width / 2, y: 0)
layer.emitterSize = CGSize(width: onView.frame.width, height: 2)
onView.layer.insertSublayer(layer, at: 0)
}
private static func getCellList(withShape: UIImage) -> [CAEmitterCell] {
var cellList = [CAEmitterCell]()
let shapeCell = CAEmitterCell()
shapeCell.contents = withShape.cgImage
shapeCell.birthRate = 5
shapeCell.lifetime = 40
shapeCell.velocity = CGFloat(55)
shapeCell.emissionLongitude = 180 * (.pi / 180)
shapeCell.emissionRange = 45 * (.pi / 180)
shapeCell.scale = 0.04
shapeCell.scaleRange = 0.05
cellList.append(shapeCell)
return cellList
}
}
@Coder-ACJHP
Copy link
Author

How to use?

EmitterProvider.createEmitterLayer(onView: view, withShape: #imageLiteral(resourceName: "snowFlake"))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment