Created
April 15, 2019 08:01
-
-
Save Coder-ACJHP/0b73d776d2b748ad9ed625c71ae0bdeb to your computer and use it in GitHub Desktop.
This file contains 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
// | |
// 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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How to use?