IOS7 中典型的tabarcontroller+navigationbarcontroller+viewcontroller组合 的一个问题解决
2014-03-25 22:57
316 查看
分割线下面的东东严重错误了,其实只要在 pushViewController之前进行.hidesBottomBarWhenPushed = YES; 就可以!(被pushd的vc不需要调用hidetab...)
原本很简单的问题,搞了复杂的搞了半天,回想下原因:知识有盲区,而且查了资料后,就顺着资料的思路在查问题...
以后遇到问题要先查stackoverflow,想好关键词就可以 大部分都可以找到解决办法。
不过,这几天的纠结也不是全无用,起码用reveal熟悉了些view结构等等。
======================================================================================================================================================分割线=====================================================================
整合原来的项目代码到IOS7下,原代码根本不是使用标题的结构做的(显示出来的navigationbar只是一个bar),并且视图间都用的是presentViewController,而非pushViewController,这样很不规范。
于是修改了结构,一般而言大多是一个navigationbar里面的第一个viewcontroller显示tabar,后续再push的话,都不显示了(参考qq等等),于是使用网上查到的隐藏tabar的方法。
更重要的是,每个navigationcontroller的rootviewcontroller也要有调用:self.hidesBottomBarWhenPushed = YES;比如:
上面的这个很重要,如果不设置,会出现某些问题:比如 当push一个viewcontroller,而这个viewcontroller的view上面有UIsearchbar及UIsearchdisplaycontroller,就会出现点击searchbar后返回,发现此时视图变短了49单位的奇怪问题,而且如果后续是present一个viewcontroller的话,当dismiss后,也会有49单位变短的现象。
上面写得很乱,有空的时候,写一个框架代码吧。
上面很可能有隐藏的问题,如果有同学知道,请指点下吧,谢谢。
原本很简单的问题,搞了复杂的搞了半天,回想下原因:知识有盲区,而且查了资料后,就顺着资料的思路在查问题...
以后遇到问题要先查stackoverflow,想好关键词就可以 大部分都可以找到解决办法。
不过,这几天的纠结也不是全无用,起码用reveal熟悉了些view结构等等。
======================================================================================================================================================分割线=====================================================================
整合原来的项目代码到IOS7下,原代码根本不是使用标题的结构做的(显示出来的navigationbar只是一个bar),并且视图间都用的是presentViewController,而非pushViewController,这样很不规范。
于是修改了结构,一般而言大多是一个navigationbar里面的第一个viewcontroller显示tabar,后续再push的话,都不显示了(参考qq等等),于是使用网上查到的隐藏tabar的方法。
//最后用 - (void)hideTabBar { if (self.tabBarController.tabBar.hidden == YES) { return; } UIView *contentView = nil; if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] ) contentView = [self.tabBarController.view.subviews objectAtIndex:1]; else contentView = [self.tabBarController.view.subviews objectAtIndex:0]; if(contentView.frame.size.height < ScreenHeight) { contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height + self.tabBarController.tabBar.frame.size.height); } self.tabBarController.tabBar.hidden = YES; } /* 虽然解决了隐藏系统TabBar,显示自定义的TabBar并且视图不会错位的问题。但是不明白原理。希望高手解答一下。或是有什么另外的方法。 PS:用以上的方法隐藏系统TabBar,在需要显示系统的TabBar的时候要另外设置 */ - (void)showTabBar { if (self.tabBarController.tabBar.hidden == NO) { return; } UIView *contentView = nil; if ([[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]]) contentView = [self.tabBarController.view.subviews objectAtIndex:1]; else contentView = [self.tabBarController.view.subviews objectAtIndex:0]; contentView.frame = CGRectMake(contentView.bounds.origin.x, contentView.bounds.origin.y, contentView.bounds.size.width, contentView.bounds.size.height - self.tabBarController.tabBar.frame.size.height); self.tabBarController.tabBar.hidden = NO; }在每个viewcontroller中都有如下代码(当然,可以写到一个类中,然后继承)
-(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; if([self.navigationController.viewControllers count] == 2) [self hideTabBar];//self.navigationController.tabBarController.tabBar.hidden = YES; } -(void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; self.hidesBottomBarWhenPushed = YES; } -(void)viewWillDisappear:(BOOL)animated { [super viewWillDisappear:animated]; if([self.navigationController.viewControllers count] == 1) [self showTabBar];//self.navigationController.tabBarController.tabBar.hidden = NO; } -(void)viewDidDisappear:(BOOL)animated { [super viewDidDisappear:animated]; // self.hidesBottomBarWhenPushed = NO; }
更重要的是,每个navigationcontroller的rootviewcontroller也要有调用:self.hidesBottomBarWhenPushed = YES;比如:
- (void) viewDidAppear:(BOOL)animated { [super viewDidAppear:YES]; self.hidesBottomBarWhenPushed = YES;//important!!
.... }
上面的这个很重要,如果不设置,会出现某些问题:比如 当push一个viewcontroller,而这个viewcontroller的view上面有UIsearchbar及UIsearchdisplaycontroller,就会出现点击searchbar后返回,发现此时视图变短了49单位的奇怪问题,而且如果后续是present一个viewcontroller的话,当dismiss后,也会有49单位变短的现象。
上面写得很乱,有空的时候,写一个框架代码吧。
上面很可能有隐藏的问题,如果有同学知道,请指点下吧,谢谢。
相关文章推荐
- 一个典型的例子解决常见的高级Windows程序设计问题
- 一个关于MFMessageComposeViewController的ios7中的诡异问题 收件人视图黑色 和解决方式
- 《解决问题1000.1》又是I2C驱动问题,产品应用上一个问题,非常简单,也比较典型,记录一下
- 一个典型的wincvs 'unrecognized response `FATAL ERROR: Network error:' 问题解决和认识
- 一个关于MFMessageComposeViewController的ios7中的诡异问题 收件人视图黑色 和解决方式
- 解决”不允许一个用户使用一个以上用户名与一个服务器或共享资源的多重连接“问题
- 6 个 Linux 运维典型问题,大牛告诉你解决思路!
- ListView中只显示一个item问题解决方法
- tabLayout 一个问题的解决方法
- 一个UTF8字符集相关问题的解决
- phonegap如何解决ios7状态栏bar显示问题
- 一个使用FFmpeg库读取3gp视频的例子-Android中使用FFmpeg媒体库(三).so文件编译过程问题的解决
- 总算解决了QT的一个诡异问题
- 一个java.lang.NoClassDefFoundError问题的解决
- 一个低概率core dump问题的解决------static搞起
- 升级iOS7遇到问题This device isn't eligible for the requested build的解决方法
- 解决IOS7中LayoutConstraint动画无效果的问题
- 解决一个问题的思路 之“解决已经写满con.close() 仍然出现"但是尚未从池中获取连接"的连接池耗尽问题”
- 解决flume运行中的一个异常问题!
- 解决了一个困扰了几个月的问题……令人郁闷……