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 / 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 / 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 / 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 / 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 / RunAlgorithmAnimated.swift
Created February 13, 2018 17:55
Syncing UIView animations - Run algorithm with animation
let options: UIViewAnimationOptions = [.allowUserInteraction, .beginFromCurrentState]
UIView.animate(withDuration: 2.5, delay: 0.0, options: options, animations: {
self.runLayoutSubviewsAlgorithm()
})
@zenangst
zenangst / ShouldAnimate.swift
Created February 13, 2018 17:53
Syncing UIView animations - Should animate example
let shouldAnimate = !(subviewsInLayoutOrder.flatMap{ $0.layer.animationKeys() }.isEmpty)
@zenangst
zenangst / ImageView.swift
Last active April 14, 2021 21:33
Round corners for image views on tvOS (Swift 4)
// A Swift 4 version of https://gist.github.com/petergp/815ba3bf6b7280c2c01f
private class ImageView : UIImageView {
private class Layer: CALayer {
override func addSublayer(_ layer: CALayer) {
defer { super.addSublayer(layer) }
let cornerRadiusKey = "_cornerRadius"
guard let configuration = layer.value(forKey: "_configuration") as? NSObject,
configuration.responds(to: NSSelectorFromString(cornerRadiusKey)) else {
return
@zenangst
zenangst / From-inspiration-to-production-part2-example1.swift
Last active May 9, 2017 18:52
From inspiration to production, Part 2 - Example 1
private func createRelatedComponents() -> [ComponentModel] {
let infoComponent = ComponentModel(
header: Item(title: "Star Wars films and television series", kind: Spots.Identifier.header),
kind: .grid,
layout: Layout(span: 1, inset: Inset(top: 0, left: 20, bottom: 30, right: 20)),
items: [Item(text: "The Star Wars films include two complete trilogies: the original trilogy released between 1977 and 1983, and the prequel trilogy released between 1999 and 2005. A third trilogy that follows the first two began in 2015. Other films have taken or will take place between the trilogy films. There have also been several Star Wars television series and television movies, with the first being released in 1978.", kind: Spots.Identifier.info)]
)
let relatedComponent = ComponentModel(
header: Item(title: "Related movies", kind: Spots.Identifier.header),
@zenangst
zenangst / ContentFactory.swift
Created May 1, 2017 19:47
From inspiration to production, Part 2
import Spots
enum MainContentType: String {
case details, reception, related
}
class ContentFactory {
func sideComponents() -> [ComponentModel] {
let posterComponent = ComponentModel(
(lldb) bt
* thread #1: tid = 0x2276c8, 0x000000011265c75a libswiftFoundation.dylib`static Foundation.IndexPath._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSIndexPath>) -> Foundation.IndexPath + 42, queue = 'com.apple.main-thread', stop reason = EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)
* frame #0: 0x000000011265c75a libswiftFoundation.dylib`static Foundation.IndexPath._unconditionallyBridgeFromObjectiveC (Swift.Optional<__ObjC.NSIndexPath>) -> Foundation.IndexPath + 42
frame #1: 0x000000010f7c1028 Spots`@objc Delegate.tableView(UITableView, didEndDisplaying : UITableViewCell, forRowAt : IndexPath) -> () + 88 at Delegate+iOS+Extensions.swift:0
frame #2: 0x0000000110a43ba9 UIKit`-[UITableView _reuseTableViewCell:withIndexPath:didEndDisplaying:] + 294
frame #3: 0x0000000110a3fca4 UIKit`-[UITableView _updateVisibleCellsNow:isRecursive:] + 2410
frame #4: 0x0000000110a74f9f UIKit`-[UITableView _performWithCachedTraitCollection:] + 110
frame #5: 0x0000000110a5bfc8