Skip to content

Instantly share code, notes, and snippets.

@dkw5877
Created April 12, 2019 20:03
Show Gist options
  • Save dkw5877/31bd026dfdf1cb285d10a64fb512caff to your computer and use it in GitHub Desktop.
Save dkw5877/31bd026dfdf1cb285d10a64fb512caff to your computer and use it in GitHub Desktop.
Example of a basic container view controller
import UIKit
final class ContainerViewController: UIViewController {
private let imageController:UIViewController
private let listController:UIViewController
init(imageController:UIViewController, listController:UIViewController) {
self.imageController = imageController
self.listController = listController
super.init(nibName: nil, bundle: nil)
}
required init?(coder aDecoder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
override func viewDidLoad() {
super.viewDidLoad()
title = "Container"
view.backgroundColor = Theme.backgroundColor
add(child: imageController, in: view)
add(child: listController, in: view)
layoutViewControllers()
}
override func viewWillLayoutSubviews() {
super.viewWillLayoutSubviews()
layoutViewControllers()
}
private func layoutViewControllers() {
let frame = view.frame
imageController.view.frame = .init(x: 0, y: 0, width: frame.width, height: frame.height * 0.40)
let yOrigin = ceil(imageController.view.frame.height/2)
let height = ceil(frame.maxY - imageController.view.frame.maxY)
listController.view.frame = .init(x: 0, y: yOrigin, width: frame.width, height: height)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment