这个对我有用。
多亏了这里某个其他线程中的提示,我找到了一个解决方案,可以仅针对一个视图控制器隐藏选项卡栏,并为从其中调用的任何视图控制器重新建立它。
这样做,我可以保持常规的导航控制器链。
这就是我最终得到的:
#define kTabBarHeight 49
- (void) hideTabBar:(BOOL)hide {
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
CGRect bounds = [UIScreen mainScreen].bounds;
float width;
float height;
width = bounds.size.width;
height = bounds.size.height;
if (hide) {
[self.tabBarController.tabBar setHidden:YES];
switch (delegate.tabBarController.interfaceOrientation) {
case UIInterfaceOrientationPortrait:
[self.tabBarController.view setFrame:CGRectMake(0,0,width,height+kTabBarHeight)];
break;
case UIInterfaceOrientationPortraitUpsideDown:
[self.tabBarController.view setFrame:CGRectMake(0,-kTabBarHeight,width,height+kTabBarHeight)];
break;
case UIInterfaceOrientationLandscapeLeft:
[self.tabBarController.view setFrame:CGRectMake(0,0,width+kTabBarHeight,height)];
break;
case UIInterfaceOrientationLandscapeRight:
[self.tabBarController.view setFrame:CGRectMake(0-kTabBarHeight,0,width+kTabBarHeight,height)];
break;
default:
break;
}
} else {
[self.tabBarController.view setFrame:CGRectMake(0,0,width,height)];
[self.tabBarController.tabBar setHidden:NO];
}
return;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
[self hideTabBar:YES];
}
- (void)viewWillAppear: (BOOL)animated {
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self hideTabBar: YES];
return;
}
- (void)viewWillDisappear: (BOOL)animated {
[self hideTabBar:NO];
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
return;
}
内联注释应解释每个语句的原因。然而,可能有更聪明的编码方式。
与隐藏状态栏和导航栏一起使用时,存在一个副作用,我不想向大家隐藏。
1.当从此导航控制器返回到调用导航控制器时,调用控制器上的状态栏和导航栏重叠,直到设备旋转一次或在前面的另一个选项卡之后再选择相关选项卡。
2.当调用视图控制器是表视图并且设备处于横屏模式时返回到该表格时,则表格以适合横屏的方向显示,但它的布局就好像它是纵向的。左上角很好,但一些表格单元格加上选项卡被隐藏在屏幕下方。右侧有一些空余空间。这也可以通过再次旋转设备来修复。
如果我找到这些小但令人讨厌的错误的解决方案,我会让您及时知道。