在 UITabBarController 下添加持久页脚

Adding a persistent footer underneath a UITabBarController

我继承了一个项目,我想在整个应用程序下方添加一个固定页脚区域。该应用程序使用的 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吗?还是我的处理方式完全错误?

谢谢 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;