iOS 显示与隐藏TabBar

作者: CCSHCoder | 来源:发表于2016-05-03 15:52 被阅读5044次

    3种方法
    第一种

    #pragma mark -隐藏TabBar
    - (void)hideTabBar {
        if (self.tabBarController.tabBar.hidden == YES) {
            return;
        }
        UIView *contentView;
        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];
        contentView.frame = CGRectMake(contentView.bounds.origin.x,  contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height + self.tabBarController.tabBar.frame.size.height);
        self.tabBarController.tabBar.hidden = YES;
        
    }
    
    #pragma mark -显示TabBar
    - (void)showTabBar {
        if (self.tabBarController.tabBar.hidden == NO)
        {
            return;
        }
        UIView *contentView;
        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];
        contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y,  contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height);
        self.tabBarController.tabBar.hidden = NO;
        
    }
    

    第二种

    //隐藏
    self.hidesBottomBarWhenPushed = YES;
    //显示
    self.hidesBottomBarWhenPushed = NO;
    

    第三种

    vc.hidesBottomBarWhenPushed = YES;
    [self.navigationController pushViewController:vc animated:YES];
    

    相关文章

      网友评论

        本文标题:iOS 显示与隐藏TabBar

        本文链接:https://www.haomeiwen.com/subject/mexrrttx.html