I want to hide my tab bar when I scroll the collection view, code is

 #pragma mark - UIScrollViewDelegate
- (void)scrollViewWillBeginDecelerating:(UIScrollView *)scrollView
{
    [self makeTabBarHidden:YES];
}

- (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView
{
    [self makeTabBarHidden:NO];
}

- (void)makeTabBarHidden:(BOOL)hide
{
    if ( [self.tabBarController.view.subviews count] < 2 )
    {
        return;
    }
    UIView *contentView;
    UIView *bradeView = [self.tabBarController.view.subviews objectAtIndex:2];

    if ( [[self.tabBarController.view.subviews objectAtIndex:0] 
             isKindOfClass:[UITabBar class]] )
    {
        contentView = [self.tabBarController.view.subviews objectAtIndex:1];
    }
    else
    {
        contentView = [self.tabBarController.view.subviews objectAtIndex:0];
    }
    //    [UIView beginAnimations:@"TabbarHide" context:nil];
    if ( hide )
    {
        contentView.frame = self.tabBarController.view.bounds;
    }
    else
    {
        contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x,
                                 self.tabBarController.view.bounds.origin.y,
                                 self.tabBarController.view.bounds.size.width,
                                 self.tabBarController.view.bounds.size.height -
                                    self.tabBarController.tabBar.frame.size.height);
    }

    self.tabBarController.tabBar.hidden = hide;
    bradeView.hidden = hide;
}

but in iOS7 ,when tab bar is hidden , there is a black bar which does not dismiss. How can I hide tabbar in iOS7?

有帮助吗?

解决方案 2

use this

-(void)viewWillAppear:(BOOL)animated
    {
        [self.navigationController setNavigationBarHidden:YES animated:animated];
        [self setHidesBottomBarWhenPushed:YES];
        [super viewWillApper:animated];
    }


        enter code here

    -(void)viewWillDisappear:(BOOL)animated
    {
        [self.navigationController setNavigationBarHidden:NO animated:animated];
        [self setHidesBottomBarWhenPushed:NO];
        [super viewWillDisapper:animated];
    }

其他提示

In your storyboard, select the view controller for which you wish to hide the tab bar, go to attributes inspector, and in the View Controller section > Extend Edges choose the checkbox Under Bottom Bars.

If your bar is opaque select also Under Opaque Bars.

BEST ANSWER, call the following method at viewDidLoad and do what @tufyx recommended! Good Luck

- (void)hideTabBar:(UITabBarController *)tabbarcontroller
{
    [tabbarcontroller.tabBar setHidden:YES];
    UIView *contentView;
    if ([[self.tableView.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]]) {
        contentView = [self.tableView.subviews objectAtIndex:1];
    } else {
        contentView = [self.tableView.subviews objectAtIndex:0];
    }
    contentView.frame = self.tableView.bounds;
}

If you are using segues like me then you should set the view controller property before push. Here is swift example :

override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
    if segue.identifier == "YOUR_SEGUE_NAME" {
        let targetVC = segue.destinationViewController as! YOUR_VIEW_CONTROLLER
        targetVC.hidesBottomBarWhenPushed = true

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