分割线下面的东东严重错误了,其实只要在 pushViewController之前进行.hidesBottomBarWhenPushed = YES; 就可以!(被pushd的vc不需要调用hidetab...)
原本很简单的问题,搞了复杂的搞了半天,回想下原因:知识有盲区,而且查了资料后,就顺着资料的思路在查问题...
以后遇到问题要先查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单位变短的现象。
上面写得很乱,有空的时候,写一个框架代码吧。
上面很可能有隐藏的问题,如果有同学知道,请指点下吧,谢谢。