Search code examples
iosobjective-cios7hiddentabbar

iOS7 can not hide tabbar, black bar


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?


Solution

  • 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];
        }