Skip to content

Instantly share code, notes, and snippets.

@michaelevensen
Created March 29, 2017 19:10
Show Gist options
  • Save michaelevensen/ca2b47a2764d1ef3c642cd99458f3a13 to your computer and use it in GitHub Desktop.
Save michaelevensen/ca2b47a2764d1ef3c642cd99458f3a13 to your computer and use it in GitHub Desktop.
Adding / removing from a containerView
func add(asChildViewController viewController: UIViewController) {
// Add Child View Controller
self.addChildViewController(viewController)
// Add Child View as Subview
self.drawerContainerView.addSubview(viewController.view)
// self.view.addSubview(viewController.view)
// Configure Child View
viewController.view.frame = self.drawerContainerView.bounds
viewController.view.autoresizingMask = [.flexibleWidth, .flexibleHeight]
// Notify Child View Controller
viewController.didMove(toParentViewController: self)
}
func remove(asChildViewController viewController: UIViewController) {
// Notify Child View Controller
viewController.willMove(toParentViewController: nil)
// Remove Child View From Superview
viewController.view.removeFromSuperview()
// Notify Child View Controller
viewController.removeFromParentViewController()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment