Skip to content

Instantly share code, notes, and snippets.

@vialyx
Created June 25, 2018 17:47
Show Gist options
  • Save vialyx/ad3795681cc2b3a923d1899927dbaa2d to your computer and use it in GitHub Desktop.
Save vialyx/ad3795681cc2b3a923d1899927dbaa2d to your computer and use it in GitHub Desktop.
//: A UIKit based Playground for presenting user interface
import UIKit
import PlaygroundSupport
final class LayerView: UIView {
override init(frame: CGRect) {
super.init(frame: frame)
configureLayers()
}
required init?(coder aDecoder: NSCoder) {
super.init(coder: aDecoder)
configureLayers()
}
private func configureLayers() {
let emitterLayer = CAEmitterLayer()
emitterLayer.emitterPosition = CGPoint(x: 100, y: 100)
let cell = CAEmitterCell()
cell.birthRate = 10
cell.lifetime = 100
cell.velocity = 500
cell.scale = 0.1
cell.spin = 1
cell.emissionRange = CGFloat.pi * 2.0
cell.contents = UIImage(named: "bytes.png")!.cgImage
emitterLayer.emitterCells = [cell]
layer.addSublayer(emitterLayer)
}
}
class MyViewController : UIViewController {
override func loadView() {
let view = UIView()
view.backgroundColor = .white
let label = UILabel()
label.frame = CGRect(x: 0, y: 200, width: 320, height: 20)
label.textAlignment = .center
label.text = "Animate with CAEmitterLayer!"
label.textColor = .black
view.addSubview(label)
let layerView = LayerView(frame: CGRect(x: 100, y: 100, width: 100, height: 100))
view.addSubview(layerView)
self.view = view
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment