OGeek|极客世界-中国程序员成长平台

标题: iphone - 按下特定选项卡[Tab Bar Application]-模板时无法隐藏TabBar [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-11 22:15
标题: iphone - 按下特定选项卡[Tab Bar Application]-模板时无法隐藏TabBar

开发者!

我目前正在开发一个使用标签栏应用程序模板的应用程序。我想做的事 是为我的应用程序模拟与第一个选项卡相对应的起始页。

所以当应用程序启动时,第一个选项卡被选中,UITabBar 不应该是可见的。 在这个“startview”中,有多个按钮的作用类似于其他选项卡,因此例如我按下按钮 #2 并按下第二个选项卡 View 并且 UITabBar 再次可见。

我的问题是我有办法隐藏栏,但 subview 没有调整到全屏。

通过使用: [self.tabBarController.tabBar setHidden:YES];

我也尝试过使用: self.hidesBottomBarWhenPushed = YES;

但它似乎没有效果,我不确定在哪里添加代码,因为我正在使用 模板。

有人知道如何使用 Tab Bar Application 模板来实现这一点吗?

我猜它应该在: - (void)tabBarControllerUITabBarController *)tabBarController didSelectViewController: (UIViewController *)viewController

但是我已经尝试过了,并且永远不会调用该方法...

非常感谢, 罗伯特



Best Answer-推荐答案


此代码可以帮助您隐藏 tabbarcontroller 并调整 viewcontroller 的大小。

    - (void) hideTabBarUITabBarController *) tabbarcontroller {

    int height = 480;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3];

    for(UIView *view in tabbarcontroller.view.subviews) {
        if([view isKindOfClass:[UITabBar class]]) {
            [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];
        } 
        else {
            [view setFrame:CGRectMake(view.frame.origin.x,view.frame.origin.y, 320, 436)];
        }
    }

    [UIView commitAnimations];
}

第二种方法可以帮助你在 View 中重新设置 tababr

    - (void) showTabBarUITabBarController *) tabbarcontroller {

    int height = 480;

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.3]; 

    for(UIView *view in tabbarcontroller.view.subviews) {

        if([view isKindOfClass:[UITabBar class]]) {
            [view setFrame:CGRectMake(view.frame.origin.x, height, view.frame.size.width, view.frame.size.height)];            
        } 
        else {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, height)];
        }
    }    

    [UIView commitAnimations];
}

在您的代码中实现之前请先理解代码...

关于iphone - 按下特定选项卡[Tab Bar Application]-模板时无法隐藏TabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9818591/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://ogeek.cn/) Powered by Discuz! X3.4