Created
December 14, 2020 03:47
-
-
Save amosgyamfi/88b138fc7be239e069692cecd1dc0a9f to your computer and use it in GitHub Desktop.
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
// | |
// Snow_BackgroungView.swift | |
// Exported from Kite Compositor for Mac 2.0.2 | |
// | |
// Created on 14.12.2020, 5.41. | |
// | |
import UIKit | |
class Snow_BackgroungView: UIView | |
{ | |
// MARK: - Initialization | |
init() | |
{ | |
super.init(frame: CGRect(x: 0, y: 0, width: 414, height: 896)) | |
self.setupLayers() | |
} | |
required init?(coder aDecoder: NSCoder) | |
{ | |
super.init(coder: aDecoder) | |
self.setupLayers() | |
} | |
// MARK: - Setup Layers | |
private func setupLayers() | |
{ | |
// Images | |
// | |
guard let imgPngImage = UIImage(named: "img.png") else { | |
fatalError("Warning: Unable to locate image named 'img.png'") | |
} | |
guard let particleTiffImage = UIImage(named: "Particle-1.tiff") else { | |
fatalError("Warning: Unable to locate image named 'Particle-1.tiff'") | |
} | |
// Colors | |
// | |
let backgroundColor = UIColor(red: 0.59, green: 0.118, blue: 0.25075, alpha: 0) | |
let borderColor = UIColor(red: 0.79, green: 0.158, blue: 0.33575, alpha: 0) | |
let color = UIColor(red: 0.999996, green: 1, blue: 1, alpha: 1) | |
let borderColor1 = UIColor(red: 0.795254, green: 0.795254, blue: 0.795254, alpha: 0) | |
let color1 = UIColor.black | |
// Fonts | |
// | |
let systemFontHeavyFont = UIFont.systemFont(ofSize: 32.0, weight: .heavy) | |
let systemFontRegularFont = UIFont.systemFont(ofSize: 32.0, weight: .regular) | |
let systemFontSemiboldFont = UIFont.systemFont(ofSize: 19.0, weight: .semibold) | |
let systemFontHeavyFont1 = UIFont.systemFont(ofSize: 19.0, weight: .heavy) | |
let systemFontRegularFont1 = UIFont.systemFont(ofSize: 19.0, weight: .regular) | |
let systemFontUltralightFont = UIFont.systemFont(ofSize: 72.0, weight: .ultraLight) | |
// snow_backgroung | |
// | |
let snowBackgroungLayer = CALayer() | |
snowBackgroungLayer.name = "snow_backgroung" | |
snowBackgroungLayer.bounds = CGRect(x: 0, y: 0, width: 414, height: 896) | |
snowBackgroungLayer.position = CGPoint(x: 0, y: 0) | |
snowBackgroungLayer.anchorPoint = CGPoint(x: 0, y: 0) | |
snowBackgroungLayer.contentsGravity = .center | |
snowBackgroungLayer.masksToBounds = true | |
snowBackgroungLayer.allowsEdgeAntialiasing = true | |
snowBackgroungLayer.allowsGroupOpacity = true | |
// snow_backgroung Sublayers | |
// | |
// background | |
// | |
let backgroundLayer = CALayer() | |
backgroundLayer.name = "background" | |
backgroundLayer.bounds = CGRect(x: 0, y: 0, width: 1278, height: 958) | |
backgroundLayer.position = CGPoint(x: -47, y: -64.031751) | |
backgroundLayer.anchorPoint = CGPoint(x: 0, y: 0) | |
backgroundLayer.contents = imgPngImage.cgImage | |
backgroundLayer.contentsGravity = .center | |
backgroundLayer.allowsEdgeAntialiasing = true | |
backgroundLayer.allowsGroupOpacity = true | |
// background Animations | |
// | |
// position.x | |
// | |
let positionXAnimation = CABasicAnimation() | |
positionXAnimation.beginTime = self.layer.convertTime(CACurrentMediaTime(), from: nil) + 0.000001 | |
positionXAnimation.duration = 12.79605 | |
positionXAnimation.fillMode = .both | |
positionXAnimation.isRemovedOnCompletion = false | |
positionXAnimation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut) | |
positionXAnimation.keyPath = "position.x" | |
positionXAnimation.toValue = -858 | |
backgroundLayer.add(positionXAnimation, forKey: "positionXAnimation") | |
snowBackgroungLayer.addSublayer(backgroundLayer) | |
// Emitter | |
// | |
let emitterLayer = CAEmitterLayer() | |
emitterLayer.name = "Emitter" | |
emitterLayer.bounds = CGRect(x: 0, y: 0, width: 414, height: 571) | |
emitterLayer.position = CGPoint(x: 206, y: -0.031751) | |
emitterLayer.anchorPoint = CGPoint(x: 0.5, y: 0) | |
emitterLayer.contentsGravity = .center | |
emitterLayer.backgroundColor = backgroundColor.cgColor | |
emitterLayer.borderWidth = 1 | |
emitterLayer.borderColor = borderColor.cgColor | |
emitterLayer.shadowOffset = CGSize(width: 0, height: 1) | |
emitterLayer.allowsEdgeAntialiasing = true | |
emitterLayer.allowsGroupOpacity = true | |
emitterLayer.fillMode = .forwards | |
emitterLayer.birthRate = 16 | |
emitterLayer.emitterDepth = 1 | |
emitterLayer.emitterShape = .cuboid | |
emitterLayer.emitterMode = .volume | |
emitterLayer.emitterPosition = CGPoint(x: 207, y: 50) | |
emitterLayer.emitterSize = CGSize(width: 414, height: 561) | |
emitterLayer.lifetime = 0.5 | |
emitterLayer.scale = 0.5 | |
emitterLayer.seed = 1 | |
emitterLayer.velocity = 2 | |
// Emitter Cell | |
// | |
let emitterCellEmitterCell = CAEmitterCell() | |
emitterCellEmitterCell.name = "Emitter Cell" | |
emitterCellEmitterCell.contents = particleTiffImage.cgImage | |
emitterCellEmitterCell.color = color.cgColor | |
emitterCellEmitterCell.scale = 0.05 | |
emitterCellEmitterCell.scaleRange = 0.2 | |
emitterCellEmitterCell.scaleSpeed = 0.03 | |
emitterCellEmitterCell.spin = 0.3 | |
emitterCellEmitterCell.spinRange = 0.1 | |
emitterCellEmitterCell.velocity = 10 | |
emitterCellEmitterCell.velocityRange = 8 | |
emitterCellEmitterCell.yAcceleration = 300 | |
emitterCellEmitterCell.zAcceleration = 50 | |
emitterCellEmitterCell.emissionRange = 6.28 | |
emitterCellEmitterCell.birthRate = 10 | |
emitterCellEmitterCell.lifetime = 5 | |
emitterCellEmitterCell.lifetimeRange = 4 | |
emitterCellEmitterCell.redRange = 0.3 | |
emitterCellEmitterCell.redSpeed = 0.5 | |
emitterCellEmitterCell.greenRange = 0.3 | |
emitterCellEmitterCell.greenSpeed = 0.5 | |
emitterCellEmitterCell.blueRange = 0.3 | |
emitterCellEmitterCell.blueSpeed = 0.5 | |
emitterCellEmitterCell.alphaRange = 0.9 | |
emitterCellEmitterCell.alphaSpeed = 0.5 | |
emitterCellEmitterCell.fillMode = .forwards | |
emitterLayer.emitterCells = [ emitterCellEmitterCell ] | |
snowBackgroungLayer.addSublayer(emitterLayer) | |
self.layer.addSublayer(snowBackgroungLayer) | |
// location | |
// | |
let locationLayer = CATextLayer() | |
locationLayer.name = "location" | |
locationLayer.bounds = CGRect(x: 0, y: 0, width: 171, height: 188) | |
locationLayer.position = CGPoint(x: 120, y: 62) | |
locationLayer.anchorPoint = CGPoint(x: 0, y: 0) | |
locationLayer.contentsGravity = .center | |
locationLayer.contentsScale = 2 | |
locationLayer.borderColor = borderColor1.cgColor | |
locationLayer.shadowOffset = CGSize(width: 0, height: 1) | |
locationLayer.magnificationFilter = .nearest | |
locationLayer.allowsEdgeAntialiasing = true | |
locationLayer.allowsGroupOpacity = true | |
locationLayer.needsDisplayOnBoundsChange = true | |
locationLayer.fillMode = .forwards | |
// location Attributed String | |
// | |
let locationAttributedString = NSMutableAttributedString(string: "Snow\nHelsinki, Finland\n\n-15") | |
locationAttributedString.setAttributes([.font: systemFontHeavyFont, .foregroundColor: color], range: NSRange(location: 0, length: 4)) | |
locationAttributedString.setAttributes([.foregroundColor: color1, .font: systemFontRegularFont], range: NSRange(location: 4, length: 1)) | |
locationAttributedString.setAttributes([.foregroundColor: color, .font: systemFontSemiboldFont], range: NSRange(location: 5, length: 10)) | |
locationAttributedString.setAttributes([.foregroundColor: color, .font: systemFontHeavyFont1], range: NSRange(location: 15, length: 7)) | |
locationAttributedString.setAttributes([.foregroundColor: color, .font: systemFontRegularFont1], range: NSRange(location: 22, length: 2)) | |
locationAttributedString.setAttributes([.foregroundColor: color, .font: systemFontUltralightFont], range: NSRange(location: 24, length: 3)) | |
locationLayer.string = locationAttributedString | |
locationLayer.isWrapped = true | |
locationLayer.alignmentMode = .center | |
self.layer.addSublayer(locationLayer) | |
} | |
// MARK: - Responder | |
override func touchesEnded(_ touches: Set<UITouch>, with event: UIEvent?) | |
{ | |
guard let location = touches.first?.location(in: self.superview), | |
let hitLayer = self.layer.presentation()?.hitTest(location) else { return } | |
print("Layer \(hitLayer.name ?? String(describing: hitLayer)) was tapped.") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment