Skip to content

Instantly share code, notes, and snippets.

View Aymenworks's full-sized avatar

Rebouh Aymen Aymenworks

View GitHub Profile
@Aymenworks
Aymenworks / Observation1.swift
Created November 15, 2020 10:51
Observation #1: Faces are falling from the sky!
import UIKit
class ViewController: UIViewController {
// MARK: Public
@IBOutlet weak var bottomView: UIView!
// MARK: Private
// Profile/Profile.swift
enum Profile {}
// Timeline/Timeline.swift
enum Timeline {}
// Messaging/Messaging.swift
enum Messaging {}
// Profile/Profile.ViewController.swift
class SearchView: UIView {
// MARK: Properties
// ...
enum AnimationState: CGFloat {
case start = 0.0, full = 0.7, finalBigSize = 1
}
@objc func startLoading() {
let animation = CABasicAnimation(keyPath: "locations")
animation.duration = 1.3
animation.fromValue = [0.0, 0.0, 0.4]
animation.toValue = [0.4, 0.9, 1]
animation.repeatCount = .infinity
gradientLayer.add(animation, forKey: "AsanaLoadingView")
}
private func setup() {
// ...
NotificationCenter.default.addObserver(self, selector: #selector(startLoading), name: UIApplication.willEnterForegroundNotification, object: nil)
startLoading()
}
private func setup() {
// ...
gradientLayer.locations = [0.0, 0.0, 0.4]
}
private func setup() {
// ...
gradientLayer.colors = [Colors.pink.cgColor, Colors.beige.cgColor, Colors.pink.cgColor]
gradientLayer.locations = [0.7, 0.9, 1]
}
private func setup() {
layer.addSublayer(gradientLayer)
gradientLayer.colors = [Colors.pink.cgColor, Colors.beige.cgColor, Colors.pink.cgColor]
gradientLayer.startPoint = CGPoint(x: 0, y: 0.5)
gradientLayer.endPoint = CGPoint(x: 1, y: 0.5)
}
class AsanaLoadingView: UIView {
// MARK: Properties
private struct Colors {
static let pink = #colorLiteral(red: 0.9294117647, green: 0.5215686275, blue: 0.568627451, alpha: 1)
static let beige = #colorLiteral(red: 0.968627451, green: 0.8274509804, blue: 0.6666666667, alpha: 1)
}
let gradientLayer = CAGradientLayer()
override func layoutSubviews() {
super.layoutSubviews()
foregroundButton.layer.cornerRadius = foregroundButton.bounds.height / 2.0
}