一.hidesBottomBarWhenPushed的使用注意点
1.使用storyboard或者xib push一个控制器
当A控制器要push一个B控制器的时候,我们可以在B控制器中 要打勾,另外这个属性只对系统的TabBar产生作用,而对我们自定义不起作用,push时不会隐藏
2.我们使用纯代码push控制器
当A控制器要push一个B控制器的时候,我们可以在B控制器中 写入这样一行代码
b.hidesBottomBarWhenPushed = YES.苹果官方文档也对这个属性做出了解释
If YES, then when this view controller is pushed into a controller hierarchy with a bottom bar (like a tab bar), the bottom bar will slide out. Default is NO.
但是写入这行代码最好写在ApushB这个方法之前,因为有时候不起作用如重写pushViewController方法时
当只有代码1,2时,并且是这样的代码执行顺序,即使是系统的TabBar也不会起作用,只有当代码是2,3时系统的TabBar隐藏功能才会有效
- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
//1. [super pushViewController:viewController animated:animated];
//2. viewController.hidesBottomBarWhenPushed = YES;
//3. [super pushViewController:viewController animated:animated];
}
3.拉线,也就是Storyboard用performSegue
self.hidesBottomBarWhenPushed = YES;
[self performSegueWithIdentifier:@"tov2" sender:nil];
self.hidesBottomBarWhenPushed = NO;
经过测试证明,此种方式只会对后面的一级生效,继续往后Push还会出现TabBar,要继续往后push也隐藏Tabbar还得使用4的方法,也建议如此!
4:拉线,在prepareForSegue函数里
-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
[segue.destinationViewController setHidesBottomBarWhenPushed:YES];
}
5:xib加载或者Storyboard用identifier获取Controller
UIViewController *v2 = [self.storyboard instantiateViewControllerWithIdentifier:@"v2"];
v2.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:v2 animated:YES];