0

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!

Community
  • 1
  • 1
AppsDev
  • 12,319
  • 23
  • 93
  • 186

1 Answers1

0

Create a new class as child of UITabBarController, than you have your custom controller class to adjust to your needs ...

Martin Mandl
  • 721
  • 3
  • 11
  • You mean, making a custom class that simply is a subclass of `UITabBarController`? I couldn't make it work... – AppsDev Jun 30 '13 at 14:57
  • I will. Since I'm trying to switch between two view controllers whose views have the same frame, could it be possible to have just one of those view controllers, and instead of animating the transition between two view controllers, animate a change of the content of that one view controller's view? – AppsDev Jun 30 '13 at 15:42
  • yes, but then you have to check if you get the intended results when you switch to another tab and back again ... – Martin Mandl Jun 30 '13 at 18:37