【发布时间】:2011-02-14 21:04:56
【问题描述】:
我正在将UITabBarController 加载到UINavigationController 中。默认情况下,UITabBarController 的 UITabBar 将其放置在视图的底部。通过使用默认选项,当应用在横向上启动时,该栏会正确显示在底部位置。
这也使得纵向显示在底部正确,(但仅当应用程序以横向模式启动时)。
如果我在纵向上启动应用程序,它似乎会在两个横向上向下移动状态栏的高度:
和肖像:
我试图产生与 CNBC 应用程序类似的效果,并在视图顶部显示 UITabBar。在查看了Mihai Damian's question 之后,我尝试自定义 UITabBar。
我只是添加了几行代码:
-(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];
}
当我尝试修改 UITabBar 的框架时,它会在横向模式下消失:
当它再次分别以横向和纵向启动时,在纵向上出现在不同的高度。
以横向模式启动:
以纵向模式启动:
以前有人遇到过这个问题吗?如果是这样,您是如何解决的?在这里的任何帮助将不胜感激。
当视图以纵向模式加载时,它似乎只是添加了状态栏的 20 像素,就好像它没有找到状态栏,即使它在那里,因此,它在已经添加的顶部添加了 20 像素状态栏现有 20 像素。
【问题讨论】:
标签: cocoa-touch ios uinavigationcontroller uitabbarcontroller uitabbar