I\'m working on a universal app, and I\'m trying to share as much code as possible between the iPhone and iPad versions. I need to use a TabBarController as my root view contro
This is a common issue when adding view controllers to a tab bar.
From Apple's documentation (Tab Bar Controllers - Tab Bars and Full-Screen Layout):
Tab bar controllers support full-screen layout differently from the way most other controllers support it. You can still set the wantsFullScreenLayout property of your custom view controller to YES if you want its view to underlap the status bar or a navigation bar (if present). However, setting this property to YES does not cause the view to underlap the tab bar view. The tab bar controller always resizes your view to prevent it from underlapping the tab bar.
In words of code, you should do the following:
UINavigationController *myNavController = [[UINavigationView alloc] init];
myNavController.wantsFullScreenLayout = YES;
//...
NSArray* controllers = [NSArray arrayWithObjects:myNavController, nil];
myTabBarController.viewControllers = controllers;
If, however, you run into the problem that when opening application in orientation other than UIInterfaceOrientationPortrait
your myNavController
's view moves 20 pix off the screen to the top, then you will have set controller's wantsFullScreenLayout
property dynamically (instead of the above solution), depending on the initial orientation.
I do it using a static variable defined in your navigation controller implementation:
static UIInterfaceOrientation _initialOrientation = -1;
After that you need to overload the viewDidAppear:
method and set the variable appropriately:
- (void)viewDidAppear:(BOOL)animated
{
if (_initialOrientation == -1)
_initialOrientation = [[UIApplication sharedApplication] statusBarOrientation];
self.wantsFullScreenLayout = (_initialOrientation != UIInterfaceOrientationPortrait);
[super viewDidAppear:animated];
}
Hope this helps.