Skip to content

Instantly share code, notes, and snippets.

@onmyway133
Last active May 15, 2016 11:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save onmyway133/9978108 to your computer and use it in GitHub Desktop.
Save onmyway133/9978108 to your computer and use it in GitHub Desktop.
View Controller Containment
// Adding A Child View Controller
[self addChildViewController:viewController];
viewController.view.frame = self.view.bounds;
[self.view addSubview:viewController.view];
[viewController didMoveToParentViewController:self];
// Removing A Child From A Parent
[viewController willMoveToParentViewController:nil];
[viewController.view removeFromSuperview];
[viewController removeFromParentViewController];
// Replace
// Containment
[self addChildViewController:vc];
[self.currentVC willMoveToParentViewController:nil];
[self transitionFromViewController:self.currentVC
toViewController:vc
duration:0.25
options:0
animations:^
{
// Do any fancy animation you like
} completion:^(BOOL finished) {
[vc didMoveToParentViewController:self];
[self.currentVC removeFromParentViewController];
self.currentVC = vc;
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment