美文网首页
iOS显示和隐藏TabBar

iOS显示和隐藏TabBar

作者: 哥只是个菜鸟 | 来源:发表于2020-06-10 15:45 被阅读0次

    显示UITabBar

    - (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;
        }
    }
    

    隐藏UITabBar

    - (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;
        }
    }
    

    相关文章

      网友评论

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

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