问题
I am loading a UITabBarController
inside a UINavigationController
. By default the UITabBar
for the UITabBarController
places it at the bottom of the view. By using the default option the bar is displayed correctly at the bottom position when the app is initiated on landscape.
This also makes portrait display correctly at the bottom, (but only when the app is initiated in landscape mode).
If I start the app on portrait, it appears to shift downwards the height of the status bar on both landscape:
and portrait:
I am trying to have a similar effect as the CNBC app and display the UITabBar
at the top of the view. After reviewing Mihai Damian's question I attempted to customize the UITabBar.
I simply added a couple of lines of code:
-(void)loadView{
UIView *contentView = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]];
contentView.backgroundColor = [UIColor clearColor];
self.view = contentView;
[contentView release];
orderingTabBarController = [[UITabBarController alloc] init];
OrderingSpecialsViewController *specialsViewController = [[OrderingSpecialsViewController alloc] initWithNibName:@"OrderingSpecialsViewController" bundle:nil];
OrderingProductViewTabBarController *productViewTabBarController = [[OrderingProductViewTabBarController alloc] init];
OrderingSummaryViewController *summaryViewController = [[OrderingSummaryViewController alloc] init];
specialsViewController.title = @"SPECIALS";
productViewTabBarController.title = @"PRODUCT";
summaryViewController.title = @"ORDER SUMMARY";
[orderingTabBarController setViewControllers:[NSArray arrayWithObjects:specialsViewController, productViewTabBarController, summaryViewController, nil] animated:YES];
orderingTabBarController.tabBar.frame = CGRectMake(0.0, 110.0, self.view.frame.size.width, 40.0);
[specialsViewController release];
[productViewTabBarController release];
[summaryViewController release];
[self.view addSubview:orderingTabBarController.view];
}
When I try modifying the frame of the UITabBar, it disappears on landscape mode:
and appears at different height on portrait when it again initiated in landscape and portrait respectively.
Initiated in landscape mode:
Initiated in portrait mode:
Has anyone encountered this problem before? If so, how did you go by solving it? Any help here would be greatly appreciated.
It just seems to add the 20 pixels of the status bar when the view is loaded on portrait mode, as if it was not finding the status bar even though it is there, hence, it adds 20 pixels on top of the already existing 20 pixels for the status bar.
回答1:
I actually fixed this through IB. The view controller for some reason wants to add a status bar, all you have to do is set that up to none on IB, and check resize view to fit. Also, make sure the dimensions of your view are set to 768 x 1024.
来源:https://stackoverflow.com/questions/4997253/why-is-my-uitabbar-shifting-down-20-pixels-when-loaded-on-portrait