Swift3.0之hidesBottomBarWhenPushed的使用和注意事项
来源:互联网 发布:linux ftp的宿主 编辑:程序博客网 时间:2024/06/05 16:50
我们有时候在开发iOS的时候,涉及到跳转界面时,需要隐藏tabbar,以便我们重新定义新的。
OC版本的:
//1.设置self.tabBarController.tabBar.hidden=YES;
self.tabBarController.tabBar.hidden=YES;
//2.如果在push跳转时需要隐藏tabBar,设置self.hidesBottomBarWhenPushed=YES;
self.hidesBottomBarWhenPushed=YES;
NextViewController *next=[[NextViewController alloc]init];
[self.navigationController pushViewController:next animated:YES];
self.hidesBottomBarWhenPushed=NO;
OC版本的:
//1.设置self.tabBarController.tabBar.hidden=YES;
self.tabBarController.tabBar.hidden=YES;
//2.如果在push跳转时需要隐藏tabBar,设置self.hidesBottomBarWhenPushed=YES;
self.hidesBottomBarWhenPushed=YES;
NextViewController *next=[[NextViewController alloc]init];
[self.navigationController pushViewController:next animated:YES];
self.hidesBottomBarWhenPushed=NO;
//注意:在push后设置self.hidesBottomBarWhenPushed=NO;
其实在OC中直接对 next.hidesBottomBarWhenPushed=YES就可以在跳转界面的时候隐藏tabbar
而不需要设置self.hidesBottomBarWhenPushed=NO;
Swift版本的:
let testVC = UIViewController()self.hidesBottomBarWhenPushed = trueself.navigationController?.pushViewController(testVC, animated: true)self.hidesBottomBarWhenPushed = false如果是push到下个界面就没有问题,如果从第二个界面push到第三个界面,再返回第二个界面,tabbar就会显示,这样还是达不到我们想要的结果
下面是我自己对hidesBottomBarWhenPushed 属性设置的一个总结,应该每一次push,都去执行对hidesBottomBarWhenPushed属性进行设置,如
果要push的界面多了,那不是做很多繁琐的工作,所以自定义了UINavigationController,对hidesBottomBarWhenPushed属性进行统一设置
import UIKitclass BaseNavigationController: UINavigationController { override func viewDidLoad() { super.viewDidLoad() // Do any additional setup after loading the view. } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } //每一次push都会执行这个方法,push之前设置viewController的hidesBottomBarWhenPushed override func pushViewController(_ viewController: UIViewController, animated: Bool) { viewController.hidesBottomBarWhenPushed = true super.pushViewController(viewController, animated: true) viewController.hidesBottomBarWhenPushed = false } override func popViewController(animated: Bool) -> UIViewController? { //以下函数是对返回上一级界面之前的设置操作 //每一次对viewController进行push的时候,会把viewController放入一个栈中 //每一次对viewController进行pop的时候,会把viewController从栈中移除 if self.childViewControllers.count == 2 { //如果viewController栈中存在的ViewController的个数为两个,再返回上一级界面就是根界面了 //那么要对tabbar进行显示 let controller:UIViewController = self.childViewControllers[0] controller.hidesBottomBarWhenPushed = false } else { //如果viewController栈中存在的ViewController的个数超过两个,对要返回到的上一级的界面设置hidesBottomBarWhenPushed = true //把tabbar进行隐藏 let count = self.childViewControllers.count-2 let controller = self.childViewControllers[count] controller.hidesBottomBarWhenPushed = true } return super.popViewController(animated: true) }}
阅读全文
1 0
- Swift3.0之hidesBottomBarWhenPushed的使用和注意事项
- swift3.0之UIImagePickerController的使用和注意事项
- hidesBottomBarWhenPushed的使用
- hidesBottomBarWhenPushed 使用
- Swift3.0学习之ScrollView的简单使用
- Swift3.0学习之CollectionView的简单使用
- swift3.0 coredata 的使用
- Swift3.0 popToViewController 的使用
- Swift3.0 popToViewController 的使用
- swift3.0:sqlite3的使用
- FMDB的基本使用和解析(Swift3.0)
- 三、swift3.0字符串和集合的基本使用
- swift3.0 GCD DispatchSourceTimer注意事项
- swift3 fileprivate和open的使用
- Swift3.0中Category的使用
- Swift3.0转场动画的使用
- swift3.0 中NSNotification 的使用
- Swift3.0按钮的基本使用
- Linux 使用pwgen命令创建随机密码
- YII2框架学习 扩展篇(三) Mixin技术
- 删除文件
- Kafka2.10<使用JavaAPI 批量发送生产数据>
- shell脚本运行java程序
- Swift3.0之hidesBottomBarWhenPushed的使用和注意事项
- 远程仓库
- jQuery的each和jQuery数组的each
- aerospike 持久化磁盘时,namespace与磁盘的关系
- HDU-5889-Barricade
- 微服务API Gateway
- HDU 2108 Shape of HDU(凸包判定)
- 添加远程库
- Vue 组件间滚动条互相影响 详情页列表页滚动条相互影响的解决方案 (或许就是你的正解)