Created
March 29, 2017 19:10
-
-
Save michaelevensen/ca2b47a2764d1ef3c642cd99458f3a13 to your computer and use it in GitHub Desktop.
Adding / removing from a containerView
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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