Skip to content

Instantly share code, notes, and snippets.

@ariok
Last active October 18, 2017 18:31
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ariok/7706798 to your computer and use it in GitHub Desktop.
Save ariok/7706798 to your computer and use it in GitHub Desktop.
Add/Remove a single child ViewController
// Add Remove child controllers to a custom container controller with Animations
// ADD THE CHILD CONTROLLER
self.childController = theChildController;
self.childController.view.frame = setupInitialChildControllerFrame();
[self addChildViewController:self.childController];
[self.view addSubview:self.childController.view];
[self.childController didMoveToParentViewController:self];
[UIView animateWithDuration:1.0
delay:0.0
usingSpringWithDamping:0.6
initialSpringVelocity:0.3
options:UIViewAnimationOptionCurveEaseIn
animations:^{
self.childController.view.frame = setupFinalChildControllerFrame();
} completion:nil
];
// REMOVE THE CHILD CONTROLLER
[self.childController willMoveToParentViewController:nil];
[UIView animateWithDuration:0.8
delay:0.0
usingSpringWithDamping:0.6
initialSpringVelocity:0.3
options:UIViewAnimationOptionCurveEaseIn
animations:^{
self.childController.view.frame = setupInitialChildControllerFrame();
} completion:^(BOOL complete){
[self.childController removeFromParentViewController];
self.childController = nil;
}];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment