Is it possible to hide the tabbar when a button is pressed to allow a full screen view of the content?

可紊 提交于 2019-11-27 03:12:32

There's a built-in way to do this:

self.hidesBottomBarWhenPushed = YES;

But you have to do this BEFORE the view is pushed. This is how you might want to use that:

ChildViewController* childVC = [[ChildViewController alloc] init];
childVC.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:childVC animated:YES];
[childVC release];

The best workaround I have found is to change the view size so that it covers the tabbar. Here's my code for hiding the statusBar, navBar, and tabBar when a row is selected:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];

if (appDelegate.navigationController.navigationBar.hidden == NO)
{
    [[UIApplication sharedApplication] setStatusBarHidden:YES animated:YES];
    [appDelegate.navigationController setNavigationBarHidden:YES animated:YES];

    [UIView beginAnimations:@"HideTabbar" context:nil];
    [UIView setAnimationDuration:.2];
    self.view.frame = CGRectMake(0,0,320,480);
    [UIView commitAnimations];
}
if (appDelegate.navigationController.navigationBar.hidden == YES)
{
    [[UIApplication sharedApplication] setStatusBarHidden:NO animated:YES];
    [appDelegate.navigationController setNavigationBarHidden:NO animated:YES];

    [UIView beginAnimations:@"ShowTabbar" context:nil];
    [UIView setAnimationDuration:.2];
    self.view.frame = CGRectMake(0,0,320,368);
    [UIView commitAnimations];
}   
}

My solution:

// Hide tab bar animated
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionFade];
[[self.view.window layer] addAnimation:animation forKey:@"layerAnimation"]; 
[self.tabBarController.tabBar setHidden:YES];

// Display tab bar animated
CATransition *animation = [CATransition animation];
[animation setType:kCATransitionFade];
[[self.view.window layer] addAnimation:animation forKey:@"layerAnimation"]; 
[self.tabBarController.tabBar setHidden:NO];

You have to add #import <QuartzCore/QuartzCore.h>

I´ve found one answer to this issue, is very simple and effective.

The solution is to set the option "Hides Bottom Bar on Push" in ALL VIEWS, VIEW CONTROLLERS and TAB BAR CONTROLLERS of your app.

You can do this in IB or by code anyway.

Hope you this helps everyone...

In order to adjust the size of your window, you first need to select the option of NONE in the status bar field, under your Attributes tab, of your Inspector window. Interface Builder will then let you change the size of your window.

In case any one needs the MonoTouch version os this cool little trick. (thanks!)

    // Method implementations
    static void hideTabBar (UITabBarController tabbarcontroller)
    {
        UIView.Animate(0.4, delegate() { 
            foreach(UIView view in tabbarcontroller.View.Subviews)
            {
                if(view.GetType()==typeof(UITabBar))
                    view.Frame=new  RectangleF(view.Frame.X, 480, view.Frame.Size.Width, view.Frame.Size.Height);
                else 
                    view.Frame=new  RectangleF(view.Frame.X, view.Frame.Y, view.Frame.Size.Width, 480);
            }
        });
    }

    static void showTabBar (UITabBarController tabbarcontroller)
    {
        UIView.Animate(0.4, delegate() { 
            foreach(UIView view in tabbarcontroller.View.Subviews)
            {
                if(view.GetType()==typeof(UITabBar))
                    view.Frame=new  RectangleF(view.Frame.X, 367, view.Frame.Size.Width, view.Frame.Size.Height);
                else 
                    view.Frame=new  RectangleF(view.Frame.X, view.Frame.Y, view.Frame.Size.Width, 367);
            }
        });
    }
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!