首页 > 学院 > 开发设计 > 正文

tabbarcontroller的tabbar的显示与隐藏

2019-11-07 23:26:22
字体:
来源:转载
供稿:网友
以导航为控制

项目中一般都会用到 TabBar 这个控件,需求是 TabBar在主界面正常显示,但Push到下一级界面时则需要隐藏,Pop回来的时候又需要显示。1、如下代码代码虽然能实现功能,但其操作繁琐又无动画效果,一般不用在此场合。

self.tabBarController.tabBar.hidden = YES;

2、一般使用这种

self.hidesBottomBarWhenPushed = YES;

注意:第2种一定要写对代码的位置,写的不对就会出现Pop回来没有TabBar的情况。

举例说明:比如现在要实现 从 ViewController1 Push到 ViewController2,在 ViewController2隐藏 TabBar的效果。我们可以在 ViewController1中这如下这样写,就可以实现其效果。

ViewController2 *VC2 = [[ViewController2 alloc] init]; VC2.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:VC2 animated:YES];3、在push之后加上self.hidesBottomBarWhenPushed = NO;4、在tabbarController上面装载新的navgationController,不要跟主控制器的navgation是同一个navgation,也就是说tabbarController可以不是window的rootViewController,但是tabbarController上面每个选项都要有自己单独的(自己是这种情况)

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        self.hidesBottomBarWhenPushed = YES;

    }

    return self;

}


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表