I have a UITabBarController
as the rootViewController
of my app, and, in addition to the viewControllers corresponding to the tab items of such UITabBarController
, I have two more viewControllers whose view I want to be a subview only for certain tab items, as I explained in this post. Those view's frame doesn't cover the whole screen, and I need to switch between them when selecting different tab items.
I found in Apple's documentation that it is possible to animate the transition between child view controllers in a custom container view controller, and I even tried with this code:
// First subview's view controller is already a child
secondViewController = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
secondViewController.view.frame = CGRectMake(0, y, secondViewController.view.frame.size.width, secondViewController.view.frame.size.height);
[self.window.rootViewController addChildViewController:secondViewController];
[firstViewController willMoveToParentViewController:nil];
[self.window.rootViewController transitionFromViewController:firstViewController
toViewController:secondViewController
duration:0.4
options:UIViewAnimationOptionTransitionFlipFromLeft
animations:nil
completion:^(BOOL done){
[secondViewController didMoveToParentViewController:self.window.rootViewController];
[firstViewController removeFromParentViewController];
}];
But, since my container view controller is not a custom one but a UITabBarController
, this doesn't work. I don´t find any example for this, how could I do this transition?
Thanks!