Skip to content

Instantly share code, notes, and snippets.

View zenangst's full-sized avatar
🥪
Reminiscing about vacation

Christoffer Winterkvist zenangst

🥪
Reminiscing about vacation
View GitHub Profile
@zenangst
zenangst / ClientSideCodeExample.swift
Created February 13, 2018 17:57
Syncing UIView animations - Client side example
let options: UIViewAnimationOptions = [.allowUserInteraction, .beginFromCurrentState]
UIView.animate(withDuration: 0.4, delay: 0.0, options: options, animations: {
self.headerViewController.view.frame.size.height = 120
self.contentViewController.view.frame.size.height = 320
self.moreViewController.view.frame.size.height = 210
})
@zenangst
zenangst / CALayer+resolveAnimationDuration.swift
Created February 13, 2018 17:58
Syncing UIView animations - CALayer extension
import UIKit
extension CALayer {
/// Resolve animation duration of the first animation using animation keys.
var resolveAnimationDuration: CFTimeInterval? {
if let firstKey = animationKeys()?.first,
let animation = animation(forKey: firstKey) {
return animation.duration
}
@zenangst
zenangst / layoutViewsExample.swift
Created February 13, 2018 18:00
Syncing UIView animations - Framework implementation
let animationDuration: TimeInterval? = subviewsInLayoutOrder
.flatMap({ $0.layer.resolveAnimationDuration }).first ?? duration
if let duration = animationDuration {
let options: UIViewAnimationOptions = [.allowUserInteraction, .beginFromCurrentState]
UIView.animate(withDuration: duration, delay: 0.0, options: options, animations: {
self.runLayoutSubviewsAlgorithm()
})
} else {
runLayoutSubviewsAlgorithm()
@zenangst
zenangst / FamilyFrameworkExample1.swift
Created February 13, 2018 20:10
Why I wrote Family framework - Example 1
let familyController = FamilyViewController()
let viewController = UIViewController()
familyController.addChildViewController(viewController)
@zenangst
zenangst / FamilyFrameworkExample2.swift
Created February 13, 2018 20:10
Why I wrote Family framework - Example 2
let familyController = FamilyViewController()
let viewController = UIViewController()
familyController.addChildViewController(viewController, height: 175)
@zenangst
zenangst / FamilyFrameworkExample3.swift
Created February 13, 2018 20:11
Why I wrote Family framework - Example 3
let familyController = FamilyViewController()
let customController = CustomViewController()
familyController.addChildViewController(customController, view: { $0.scrollView })
@zenangst
zenangst / Example1.swift
Last active February 16, 2018 07:44
Setting a background color to an NSView - iOS Example
import UIKit
let frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
let view = UIView(frame: frame)
view.backgroundColor = UIColor.blue
@zenangst
zenangst / Example2.swift
Created February 16, 2018 07:17
Setting a background color to an NSView - macOS Example
import Cocoa
let frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
let view = NSView(frame: frame)
view.wantsLayer = true
view.layer?.backgroundColor = NSColor.blue.cgColor
@zenangst
zenangst / Example1.swift
Created February 16, 2018 10:39
How to write an NSViewController without interface builder - Example 1
import UIKit
class MyViewController: UIViewController {}
let frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
let viewController = MyViewController()
viewController.view.frame = frame
@zenangst
zenangst / Example2.swift
Created February 16, 2018 11:00
How to write an NSViewController without interface builder - Example 2
import Cocoa
class MyViewController: NSViewController {}
let frame = CGRect(origin: .zero, size: CGSize(width: 100, height: 100))
let viewController = MyViewController()
viewController.view.frame = frame