Hi I am developing an iPad application. I used to custom tab bar. Also tabbar buttons on left side of screen. I want to see full screen. So I tried this code for hide tabbar, but did not hide. I see gray space in screen bottom. Gary space height is IOS 7 about 49 px but IOS 6 about 20 px. What can I do.

- (void)hideTabBar
{
    for(UIView *view in self.view.subviews)
    {
        if([view isKindOfClass:[UITabBar class]])
        {
            view.hidden = YES;
            break;
        }
    }
}

Gray space in IOS 7

有帮助吗?

解决方案

You can do something like this,

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

    }

Note: this is tested in ios 6 and earlier versions, so if you want to run in ios 7 and more set frame and some flag for frame.

其他提示

In the custom UITabBar view controller in viewDidLoad

  [self.tabBar setHidden:YES];
  [self.view addSubview:self.viewButton]; // you custom buttons array view

Apple's implementation is more elegant as it stretches the UITabBarController view size enough to get its tabBar outside the screen, and at the same time it will automatically stretch the views of the contained view controllers.

If you just hide your tab bar, either there is no content "under it" (your gray space) or it won't recognize taps.

You should better subclass UITabBar and draw it a you like but still let UITabBarController show and hide it properly for you.

Edit:

Just realized that hiding the tab bar is not in the default SDK but in a category I made long time ago.

Anyway stretching UITabBarController's view frame seems to me the most elegant way to "hide" the tab bar (actually move it away from the screen) as you don't have to deal with subviews or hunt down the tab bar frame directly.

Related to this question.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top