Skip to content

Instantly share code, notes, and snippets.

@amosgyamfi
Created December 23, 2020 03:30
Show Gist options
  • Save amosgyamfi/0fdf3d0ff00e54bbed5a2184eea929f6 to your computer and use it in GitHub Desktop.
Save amosgyamfi/0fdf3d0ff00e54bbed5a2184eea929f6 to your computer and use it in GitHub Desktop.
//
// 1080TvView.swift
// Exported from Kite Compositor for Mac 2.0.2
//
// Created on 23.12.2020, 4.35.
//
import UIKit
class 1080TvView: UIView
{
// MARK: - Initialization
init()
{
super.init(frame: CGRect(x: 0, y: 0, width: 1920, height: 1080))
self.setupLayers()
}
required init?(coder aDecoder: NSCoder)
{
super.init(coder: aDecoder)
self.setupLayers()
}
// MARK: - Setup Layers
private func setupLayers()
{
// Images
//
guard let tVPngImage = UIImage(named: "1080TV.png") else {
fatalError("Warning: Unable to locate image named '1080TV.png'")
}
guard let pastedImageTiffImage = UIImage(named: "PastedImage-1.tiff") else {
fatalError("Warning: Unable to locate image named 'PastedImage-1.tiff'")
}
// Colors
//
let backgroundColor = UIColor(red: 0, green: 0, blue: 0, alpha: 0)
// 1080TV
//
let tVLayer = CALayer()
tVLayer.name = "1080TV"
tVLayer.bounds = CGRect(x: 0, y: 0, width: 1970, height: 1170)
tVLayer.position = CGPoint(x: -25, y: -25)
tVLayer.anchorPoint = CGPoint(x: 0, y: 0)
tVLayer.contents = tVPngImage.cgImage
tVLayer.contentsGravity = .center
tVLayer.shadowOffset = CGSize(width: 0, height: 1)
tVLayer.allowsEdgeAntialiasing = true
tVLayer.allowsGroupOpacity = true
self.layer.addSublayer(tVLayer)
// Screen
//
let screenLayer = CALayer()
screenLayer.name = "Screen"
screenLayer.bounds = CGRect(x: 0, y: 0, width: 1920, height: 1080)
screenLayer.position = CGPoint(x: 0, y: 0)
screenLayer.anchorPoint = CGPoint(x: 0, y: 0)
screenLayer.contentsGravity = .center
screenLayer.masksToBounds = true
screenLayer.backgroundColor = backgroundColor.cgColor
screenLayer.borderColor = backgroundColor.cgColor
screenLayer.shadowOffset = CGSize(width: 0, height: 1)
screenLayer.allowsEdgeAntialiasing = true
screenLayer.allowsGroupOpacity = true
// Screen Sublayers
//
// Image Layer
//
let imageLayerLayer = CALayer()
imageLayerLayer.name = "Image Layer"
imageLayerLayer.bounds = CGRect(x: 0, y: 0, width: 756, height: 1134)
imageLayerLayer.position = CGPoint(x: 580, y: -23)
imageLayerLayer.anchorPoint = CGPoint(x: 0, y: 0)
imageLayerLayer.contents = pastedImageTiffImage.cgImage
imageLayerLayer.contentsGravity = .resizeAspect
imageLayerLayer.shadowOffset = CGSize(width: 0, height: 1)
imageLayerLayer.allowsEdgeAntialiasing = true
imageLayerLayer.allowsGroupOpacity = true
imageLayerLayer.fillMode = .forwards
// Image Layer Animations
//
// filters.Droste.inputRotation
//
let filtersDrosteInputRotationAnimation = CABasicAnimation()
filtersDrosteInputRotationAnimation.beginTime = self.layer.convertTime(CACurrentMediaTime(), from: nil) + 0.000001
filtersDrosteInputRotationAnimation.duration = 10
filtersDrosteInputRotationAnimation.speed = 0.5
filtersDrosteInputRotationAnimation.repeatCount = 1200
filtersDrosteInputRotationAnimation.fillMode = .forwards
filtersDrosteInputRotationAnimation.isRemovedOnCompletion = false
filtersDrosteInputRotationAnimation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
filtersDrosteInputRotationAnimation.keyPath = "filters.Droste.inputRotation"
filtersDrosteInputRotationAnimation.toValue = 6
filtersDrosteInputRotationAnimation.fromValue = 0
imageLayerLayer.add(filtersDrosteInputRotationAnimation, forKey: "filtersDrosteInputRotationAnimation")
// filters.Droste.inputZoom
//
let filtersDrosteInputZoomAnimation = CABasicAnimation()
filtersDrosteInputZoomAnimation.beginTime = self.layer.convertTime(CACurrentMediaTime(), from: nil) + 0.005
filtersDrosteInputZoomAnimation.duration = 10
filtersDrosteInputZoomAnimation.speed = 0.5
filtersDrosteInputZoomAnimation.repeatCount = 1200
filtersDrosteInputZoomAnimation.fillMode = .forwards
filtersDrosteInputZoomAnimation.isRemovedOnCompletion = false
filtersDrosteInputZoomAnimation.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
filtersDrosteInputZoomAnimation.keyPath = "filters.Droste.inputZoom"
filtersDrosteInputZoomAnimation.toValue = 5
filtersDrosteInputZoomAnimation.fromValue = 0
imageLayerLayer.add(filtersDrosteInputZoomAnimation, forKey: "filtersDrosteInputZoomAnimation")
screenLayer.addSublayer(imageLayerLayer)
self.layer.addSublayer(screenLayer)
}
// 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