Created
August 3, 2016 12:56
-
-
Save xtrinch/a920330f0b15b6079fd5716b82fd5514 to your computer and use it in GitHub Desktop.
Add and remove childviewcontroller in swift
This file contains 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
// in parent view controller | |
@IBAction func showChildViewController(sender: AnyObject) { | |
let testController = self.storyboard!.instantiateViewControllerWithIdentifier("Test") as! Test | |
self.addChildViewController(testController) | |
self.view.addSubview(testController.view) | |
testController.view.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height) | |
testController.didMoveToParentViewController(self) | |
} | |
// in child view controller | |
@IBAction func dismissTapped(sender: AnyObject) { | |
self.view.removeFromSuperview() | |
self.removeFromParentViewController() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment