我已经继承了一个项目,我想在整个应用程序下面添加一个持久的页脚区域。该应用使用的UITabBarController
始终显示在登录屏幕之外。 tabBarController
创建如下:
UITabBarController *tabBarController = [[UITabBarController alloc] init];
UIStoryboard *sb1 = [UIStoryboard storyboardWithName:@"SB1" bundle:nil];
// ... same for sb2 and sb3
[tabBarController setViewControllers:@[sb1, sb2, sb3]];
[tabBarController setSelectedIndex:0];
我已经尝试手动设置tabBarController.size.height
,但它似乎没有任何效果。我以前从未使用storyboards
,使用它们时有什么方法可以initWithFrame
吗?或者我是以完全错误的方式接近这个?
答案 0 :(得分:0)
感谢werediver,你让我走上正轨。我通过将UITabBarController添加为子视图控制器然后手动添加其视图来实现它。
const CGFloat FOOTER_HEIGHT = 20;
// Set up tab bar area
CGRect contentFrame = [UIApplication sharedApplication].delegate.window.frame;
contentFrame.size.height -= FOOTER_HEIGHT;
UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.view.frame = contentFrame;
// Set up footer
CGRect footerFrame = contentFrame;
footerFrame.origin.y = contentFrame.size.height;
footerFrame.size.height = FOOTER_HEIGHT;
UIView *footer = [[UIView alloc] initWithFrame:footerFrame];
// Create outer view controller
UIViewController *outer = [[UIViewController alloc] init];
[outer addChildViewController:tabBarController];
[outer.view addSubview:tabBarController.view];
[outer.view footer];
[[UIApplication sharedApplication] keyWindow].rootViewController = outer;