ios - 贪婪的 UITabBarController?

标签 ios cocoa uiviewcontroller uitabbarcontroller

我正在制作一个自定义的 UIViewController,它包含 subview Controller 。它们以这种方式放在主视图 Controller 中:

- (void) setHeaderViewController:(UIViewController *)vc
{
    [self setViewController:vc isHeader:YES];
    _headerViewController = vc;
}

- (void) setDetailViewController:(UIViewController *)vc
{
    [self setViewController:vc isHeader:NO];
    _detailViewController = vc;
}

- (void) setViewController:(UIViewController*) viewController isHeader:(BOOL)isHeader
{
    UIViewController* viewControllerRef = ((isHeader) ? _headerViewController : _detailViewController);
     
    if(viewControllerRef == viewController)
         return;
     
    const CGSize selfSize = self.view.frame.size;
    
    CGRect viewFrame;
    
    if (isHeader)
    {
        viewFrame = CGRectMake(0, 0, selfSize.width, 150);
    }
    else
    {
        viewFrame = CGRectMake(0, 150, selfSize.width, selfSize.height-150);
    }

    UIView* viewControllerView = viewController.view;
    
    [viewControllerView setFrame:viewFrame];
    [viewControllerView setAutoresizingMask:(UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | ((isHeader) ? UIViewAutoresizingFlexibleBottomMargin : UIViewAutoresizingFlexibleTopMargin))];
    
    [self.view addSubview:viewControllerView];
}

如果我在每个 subview Controller 插槽中放置两个 UIViewController,则方法中定义的大小将得到遵守。然而,当放置一个 UITabBarController 时,它变得贪婪并占据了整个空间:

UIViewController *vc = [[WIFCustomerDetailHeaderViewController alloc] initWithNibName:@"WIFCustomerDetailHeaderViewController" bundle:nil];
[self setHeaderViewController:vc];

UIViewController *vc1 = [[UIViewController alloc] init];
vc1.title = @"Personal Data";
vc1.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Personal Data" image:nil tag:0];
vc1.view.backgroundColor = [UIColor redColor];
vc1.view.frame = CGRectMake(0,400,100,100);

UIViewController *vc2 = [[UIViewController alloc] init];
vc2.title = @"Diagnosis";
vc2.tabBarItem = [[UITabBarItem alloc] initWithTitle:@"Diagnosis" image:nil tag:0];
vc2.view.backgroundColor = [UIColor purpleColor];
vc2.view.frame = CGRectMake(0,500,50,50);

NSArray *tabs = [[NSArray alloc] initWithObjects:vc1, vc2, nil];

WIFCustomerDetailTabViewController *tvc = [[WIFCustomerDetailTabViewController alloc] init];
[tvc setViewControllers:tabs];

[self setDetailViewController:tvc];

有人知道这里会发生什么吗?我找不到原因...

下面的图片..

Two sub view controllers enter image description here

最佳答案

UITabBarController 类的文档说,“您必须将此 View 安装为窗口的根目录。与其他 View Controller 不同,选项卡栏界面不应该作为另一个 View Controller 的子项安装”.

您似乎正在尝试一种特别不受支持的设计。

关于ios - 贪婪的 UITabBarController?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13086630/

相关文章:

ios - Xcode 9.4 fatal error : lipo: can't open input file (No such file or directory)

objective-c - 如何从 NSString 中删除隐藏字符?

objective-c - 从窗口坐标转换 NSPoint

uiviewcontroller - 如何移动到多个 View Controller ?

ios - map View 不关注注释

ios - 如何处理跳回 iOS 中的先前屏幕

ios - 界面 View Controller !不符合协议(protocol) "LogicValue"

ios - Gdx-Pay iOS商店,找不到产品信息

ios - 带有内容框架更新关闭的 SwiftUI ScrollView

ios - 在主线程上运行 NSURLSession 完成处理程序