xcode无法隐藏tabbarcontroller

发布于 2024-12-21 10:07:59 字数 352 浏览 1 评论 0原文

我有一个 tabbarcontroller 作为主控制器,当推送视图时我想隐藏它。我使用 hidesBottomBarWhenPushed 但不起作用。谢谢。

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

I have a tabbarcontroller as main controller and when a view is pushed I would like to hide it. I use hidesBottomBarWhenPushed but not working. Thanks.

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        self.hidesBottomBarWhenPushed = YES;
    }
    return self;
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

时光无声 2024-12-28 10:07:59

当您推送此控制器时,尝试在其父视图控制器中添加此行:

    YourViewController *controller = [[YourViewController alloc]init....];
    controller.hidesBottomBarWhenPushed = YES;
    //then push the view controller

祝你好运

try to add this line when you push this controller, in it's parent view controller :

    YourViewController *controller = [[YourViewController alloc]init....];
    controller.hidesBottomBarWhenPushed = YES;
    //then push the view controller

Good Luck

GRAY°灰色天空 2024-12-28 10:07:59

仅当 tabBarController 的 viewController 之一是 UINavigationController 时,这才有效。仅当视图控制器被推送到 UINavigationController 的堆栈上时,才会考虑 hidesBottomBarWhenPushed 属性,并且如果它是根视图控制器,则不会执行太多操作。

This will only work if one of the viewControllers of the tabBarController is a UINavigationController. The hidesBottomBarWhenPushed property is only respected if a view controller is pushed onto the stack of a UINavigationController and will not do much if it is the root view controller.

残月升风 2024-12-28 10:07:59

我已经实现了自己的自定义 tabBarController (它扩展了原始的 UITabBarController ),因为我需要在某些情况下(例如设备旋转)以编程方式切换栏,这是我的实现(注释解释了它是如何工作的) :

- (void)hideBottomBar:(BOOL)hide
{
    @try 
    {
        // UITabBarController has 2 subviews:
        // - the first (index:0) is that one containing the active view controller's view
        // - the second (index:1) is that one containing the UITabBar (self.tabBar)
        UIView *topView = [self.view.subviews objectAtIndex:0];
        UIView *bottomView = [self.view.subviews objectAtIndex:1];

        // hide tabs container if necessary
        [bottomView setHidden:hide];

        // adjust frame
        if (hide) 
        {
            // expand main view to fit available space
            [topView setFrame:self.view.bounds];
        }
        else
        {
            // restore main view frame
            CGRect frame = topView.frame;
            frame.size.height -= bottomView.frame.size.height;
            [topView setFrame:frame];
        }
    }
    @catch (NSException *exception) 
    {
        [[GTMLogger sharedLogger] logError:@"Error occured adjusting tabs view: %@", exception.description];
    }
}

I've implemented my own custom tabBarController (which extends the original UITabBarController), because I need to toggle bars programmatically under certain circumstances (like device rotation), this is my implementation (comments explain how it works):

- (void)hideBottomBar:(BOOL)hide
{
    @try 
    {
        // UITabBarController has 2 subviews:
        // - the first (index:0) is that one containing the active view controller's view
        // - the second (index:1) is that one containing the UITabBar (self.tabBar)
        UIView *topView = [self.view.subviews objectAtIndex:0];
        UIView *bottomView = [self.view.subviews objectAtIndex:1];

        // hide tabs container if necessary
        [bottomView setHidden:hide];

        // adjust frame
        if (hide) 
        {
            // expand main view to fit available space
            [topView setFrame:self.view.bounds];
        }
        else
        {
            // restore main view frame
            CGRect frame = topView.frame;
            frame.size.height -= bottomView.frame.size.height;
            [topView setFrame:frame];
        }
    }
    @catch (NSException *exception) 
    {
        [[GTMLogger sharedLogger] logError:@"Error occured adjusting tabs view: %@", exception.description];
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文