hidesBottombarWhenPushed的副作用
在UITabbarController包含的UINavigationController应用中,如果UINavigationController某一页(某个level)需要隐藏Tabbar,之前的做法是在push那一页之前,将那一页的ViewController中的hidesBottombarWhenPushed参数设为YES,这样当那一页push进UINavigationController中时,底部的Tabbar就会隐藏掉。
但是这种方法有一个潜在的而又巨大的问题,假设现在我有3个ViewController A,B,C,其中为Navigation的RootViewController,A中push B,B中push C。这时,如果我想要在B中隐藏Tabbar,而在C中显示Tabbar,根据最朴素的想法就是:
|
1
2
3
4
5
6
7
8
9
|
//SecondLevel即为B,此代码在A中进行SecondLevelViewController *_2vc = [[SecondLevelViewController alloc]initWithNibName:@"SecondLevelViewController" bundle:nil]; _2vc.hidesBottomBarWhenPushed = YES; [self.navigationController pushViewController:_2vc animated:YES]; //ThirdLevel即为C,此代码在B中进行ThirdLevelViewController *_3vc = [[ThirdLevelViewController alloc]initWithNibName:@"ThirdLevelViewController" bundle:nil]; _3vc.hidesBottomBarWhenPushed = NO; [self.navigationController pushViewController:_3vc animated:YES]; |
然而很可惜,虽然A中push B能让Tabbar隐藏,但是B中push C,就没办法让Tabbar显示出来了。这是一个比较郁闷的问题,我只能猜想其中的原理是,当设置某一层hidesBottomBarWhenPushed = YES之后,UITabbarController就像不存在一样,就连调用self.tabbarController或者self.navigationController.tabbarController也应该是nil。
所以解决办法只能是手动隐藏Tabbar。
在B中,加入以下代码:
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
- (void) hideTabBar:(UITabBarController *) tabbarcontroller { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)]; } } [UIView commitAnimations];}- (void) showTabBar:(UITabBarController *) tabbarcontroller { [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { NSLog(@"%@", view); if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)]; } } [UIView commitAnimations]; }-(void)viewWillAppear:(BOOL)animated{ [super viewWillAppear:animated]; [self hideTabbar:self.tabbarController];}-(void)viewWillDisAppear:(BOOL)animated{ [super viewWillDisAppear:animated]; [self showTabbar:self.tabbarController];} |
以上代码参考了 http://stackoverflow.com/questions/5272290/how-to-hide-uitabbarcontroller
hidesBottombarWhenPushed的副作用的更多相关文章
- 隐藏tabbar的属性hidesBottomBarWhenPushed
项目中有需求是A视图控制器push之后B视图控制器需要隐藏底部的tabbar,在pop之后A视图控制器仍然显示tabbar. 其实不需要在push操作时敲 self.hidesBottomBarWhe ...
- c语言中的副作用!!千万小心!
今天刚看完书上的副作用,博主觉得呢,副作用其实就在改变变量的值,也就是一个赋值操作!不过刚刚在知道上还是犯了错!!尴尬啊!! 大家都知道,c语言中的赋值操作符是自右向左结合的!! 下面有一个关于赋值中 ...
- 如何用java写出无副作用的代码
搞java的同学们可能对无副作用这个概念比较陌生,这是函数式编程中的一个概念,无副作用的意思就是: 一个函数(java里是方法)的多次调用中,只要输入参数的值相同,输出结果的值也必然相同,并且在这个函 ...
- CSS 浮动副作用 ,清除浮动
参考:http://www.divcss5.com/jiqiao/j406.shtml 副作用:一般是一个盒子里使用了CSS float浮动属性,导致父级对象盒子不能被撑开,背景色不显示(如果父级不设 ...
- 浅谈C/C++中的顺序点和副作用
一.副作用(side effect) 表达式有两种功能:每个表达式都产生一个值( value ),同时可能包含副作用( side effect ).副作用是指改变了某些变量的值. 如: 1:20 ...
- C语言的本质(8)——副作用与顺序点
C 语言中,术语副作用是指对数据对象或者文件的修改.例如以下语句 var = 99; 的副作用是把 var 的值修改成 99.对表达式求值也可能产生副作用,例如: se = 100 对这个表达式求值所 ...
- tabBar隐藏与显现 hidesBottomBarWhenPushed
这个问题说简单也简单 但是如果不知道 可会让很多人吃苦 隐藏UITabBarController的tabBar, 我用它的一个属性hidesBottomBarWhenPushed隐 藏了,可以pop ...
- 变形transform的副作用
前面的话 变形transform本来是一个用来处理移动.旋转.缩放和倾斜等基本操作的CSS3属性,但该属性除了完成其本职工作之后,还对普通元素造成了意想不到的影响,本文将详细介绍transform ...
- cloudbase-init 自动扩盘的副作用 - 每天5分钟玩转 OpenStack(154)
这是 OpenStack 实施经验分享系列的第 4 篇. cloudbase-init 的一项功能是自动扩展 windows 的 C 盘.比如 windows 镜像是 20G,在部署 instance ...
随机推荐
- grunt///////////////////z
1. 前言 替代grunt的其他工具,例如gulp.Gulp未来有可能替代grunt,现在市场占有率不如grunt. 本文讲解grunt入门,以及讲解grunt最常用的几个插件的使用.我录制的视 ...
- Normalize.css 与 reset.css
Normalize.css 与 reset.css都是初始化页面样式 不同点在于 reset.css更加粗暴,直接把所有的样式全部初始化了: Normalize.css还剩点良心,还保留了一些浏览器默 ...
- 初识Python第二天(1)
在Python中,一切事物都是对象,对象是基于类创建的,对象继承了类的属性,方法等. 一.传递参数 1.1新建python文件,名为twoday_args.py,输出以下代码 import sys p ...
- logback.xml日志配置
日志先行,日志是程序员的眼睛 控制台输出 <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAp ...
- Spring整合Hibernate。。。。
环境搭建,在eclipse中导入spring和hibernate框架的插件,和导入所有使用到的架包 首先,hibernate的创建: 建立两个封装类,其中封装了数据库中表的属性,这儿只写属性,gett ...
- Doctrine2 SQL语句
$q = Doctrine_Query::create() ->update('WebusersTable q') ->set('q.login_name','?','John') ) - ...
- CSS 高级语法 ---- 继承和选择器的分组
1. 选择器的分组 ————————————————————————— 可以对选择器进行分组,被分组的选择器享用共同的声明. h1,h2,h3,h4,h5,h6 { color: green; ...
- python matplotlib 中文显示参数设置
python matplotlib 中文显示参数设置 方法一:每次编写代码时进行参数设置 #coding:utf-8import matplotlib.pyplot as pltplt.rcParam ...
- Java开发中经典的小实例-(do{}while())
import java.util.Scanner;public class Test13 { public static void main(String[] args) { // ...
- linux 双网卡实现
linux实现双网卡,在虚拟机中创建一个新网卡,NAT方式连接,其中eth0设置为连接外网,目前eth0为自动分配状态,所以将代码注释掉了,eth1设置为连接内网.