首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何隐藏uitabbarcontroller

如何隐藏uitabbarcontroller
EN

Stack Overflow用户
提问于 2011-03-11 19:24:55
回答 11查看 59K关注 0票数 75

我对UITabBarController有个问题。在我的应用程序中,我想隐藏它,但不使用hidesBottomBarWhenPushed,因为我想隐藏它,而不是在推送它时隐藏它。例如,当我在应用程序中按下隐藏按钮时,我想隐藏它。

我在谷歌上读了很多文章,但我找不到我该怎么做。

EN

回答 11

Stack Overflow用户

发布于 2012-07-15 16:49:54

修改了Setomidor的答案,以便同时适用于横向、纵向和iPad ( 320和480值仅适用于iPhone)。

代码语言:javascript
复制
- (void) hideTabBar:(UITabBarController *) tabbarcontroller 
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    float fHeight = screenRect.size.height;
    if(  UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width;
    }

    for(UIView *view in tabbarcontroller.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];
        } 
        else 
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
            view.backgroundColor = [UIColor blackColor];
        }
    }
    [UIView commitAnimations];
}



- (void) showTabBar:(UITabBarController *) tabbarcontroller 
{   
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float fHeight = screenRect.size.height - tabbarcontroller.tabBar.frame.size.height;

    if(  UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width - tabbarcontroller.tabBar.frame.size.height;
    }

    [UIView beginAnimations:nil context:NULL];
    [UIView setAnimationDuration:0.5];
    for(UIView *view in tabbarcontroller.view.subviews)
    {   
        if([view isKindOfClass:[UITabBar class]])
        {
            [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)];            
        } 
        else 
        {
            [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)];
        }       
    }
    [UIView commitAnimations]; 
}

我还修改了代码,以处理UIDevice方向更改在iOS 6中引入的更改,并确保即使在设备仰卧时也能正常工作。

票数 58
EN

Stack Overflow用户

发布于 2011-03-11 19:29:47

在按钮的操作方法中:

代码语言:javascript
复制
[self.tabBarController.tabBar setHidden:YES];
票数 34
EN

Stack Overflow用户

发布于 2012-06-14 17:51:22

Saurabh上面的答案可以扩展到也适用于横向:

代码语言:javascript
复制
+ (void) hideTabBar:(UITabBarController *) tabbarcontroller {

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

    //Support for landscape views
    int orientation = [[UIDevice currentDevice] orientation];
    int x_pos = 480;
    if (orientation == UIInterfaceOrientationLandscapeLeft || orientation == UIInterfaceOrientationLandscapeRight) {
        x_pos = 320;
    }

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

`

showTabBar()对应的x_pos编号是431271

票数 9
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5272290

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档