今天写项目时遇到了一个问题:一个自定义的tabbar(继承了系统的UITabBarController),用导航的push跳转到下一个页面时想隐藏该tabbar,用
hidesBottomBarWhenPushed
没有起作用,原来hidesBottomBarWhenPushed适用于系统的tabbar,自定义的tabbar不能通过hidesBottomBarWhenPushed属性简单的设置。以下是我的解决方法:
1.在自定义tabbar的页面,添加如下方法
-(void)setHidesBottomBarWhenPushed:(BOOL)hidesBottomBarWhenPushed
{
myTabBarView.hidden = hidesBottomBarWhenPushed;
}
图中myTabBarView是自定义的假tabbar,是个UIView。
该方法相当于重写了系统UITabBarController中的属性
hidesBottomBarWhenPushed
2.在要隐藏tabbar的页面添加如下两个方法
-(void)viewWillAppear:(BOOL)animated
{
self.tabBarController.hidesBottomBarWhenPushed = YES;
}
-(void)viewWillDisappear:(BOOL)animated
{
self.tabBarController.hidesBottomBarWhenPushed = NO;
}
相当于每次页面出现和消失的时候都重新设置了自定义tabbar是否隐藏
这样就ok啦。还可以优化,如果要隐藏tabbar的页面多,可以写一个父类,把这两个方法放在父类中,要隐藏tabbar的页面继承该父类即可。