UITabBarController Without a UITabBar

南楼画角 提交于 2019-12-11 07:47:14

问题


I'v been trying to hide/remove the UITabBar from a UITabBarController. I've got a UITabBar in my iPhone version but I've moved the navigation to a new view controller for the iPad version. The new menu works using the UITabBarDelegate methods to switch between the UIViewControllers.

So far so good.

All I need now is to somehow hide the UITabBar.

I've got a custom UITabBarController and I've tried simply using self.tabBar.hidden = YES; but i need the view to fill the screen.

Thank you


回答1:


So you have a few options. Suppose that your tab views are navigation controllers. In that case you can have a temporary viewController that immediately pushes the "real" viewController you want to use, and the "real" one has the method below implemented. Later, by resetting the navigationControllers viewControllers array, you can get rid of the temporary controller for good.

- (BOOL) hidesBottomBarWhenPushed { return YES; }

If that does not work for you, then you can play games with the window.rootViewController. At launch, you create your viewController and make it the rootViewController. Later, when you want a tab bar, you can message back to the appDelegate to create a tabBarController and make your view the first viewController (as is!). I just verified this in a simple demo app using the Xcode Tab Bar project. Here is the code I used:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    viewController1 = [[FirstViewController alloc] initWithNibName:@"FirstViewController" bundle:nil];

    self.window.rootViewController = viewController1;
    [self.window makeKeyAndVisible];
    return YES;
}

- (void)switcher
{
    [viewController1.view removeFromSuperview];
    UIViewController *viewController2 = [[SecondViewController alloc] initWithNibName:@"SecondViewController" bundle:nil];
    self.tabBarController = [[UITabBarController alloc] init];
    self.tabBarController.viewControllers = [NSArray arrayWithObjects:viewController1, viewController2, nil];
    self.window.rootViewController = self.tabBarController;
}



回答2:


Ive Found the answer I was looking for

Hope this is helpful to someone else

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

    }


来源:https://stackoverflow.com/questions/11544005/uitabbarcontroller-without-a-uitabbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!