当屏幕方向改变时隐藏UITabBar

7

我有一个非常简单的问题,但答案并不容易。

当我的屏幕方向改变时,我想隐藏UITabBar。

我找了两种方法:

框架方式

myAppDelegate.tabBarController.tabBar.frame = CGRectMake(<<bottomOfScreen>>);

这个功能正常运行但有一个空白区域,因此我尝试调整tabBarController.view.frame和myViewController.view.frame,但是没有取得好的结果。

导航控制器方法

myOtherVC.hideTabBarWhenPushed = YES;
[self.navigationController pushViewController:myOtherVC animated:NO];

这个解决方案可以工作,但不适合我的应用。

更新:

[appDelegate.tabBarController.view removeFromSuperview];
[self.view removeFromSuperview]; [appDelegate.window addSubview:self.view];
self.view.frame = CGRectMake(0,0,480,320);

功能正常,但不再自动旋转(当然,我没有更改shouldAutorotate,并且它始终返回YES)


如何隐藏我的 tabBar 并使当前视图占据其空间?


谢谢


你想出如何做了吗?如果是的话,可以分享一下答案吗? - Steven Fisher
是的,我刚刚发布了答案。 - Francescu
2个回答

3
您可以将当前解决方案与以下内容结合使用:
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

检测旋转。(我认为您可以将其与view.transform = CGAffineTransformMakeRotation相结合,使其旋转...?)


0

我认为你可以轻松地采取以下两种方法:

  1. 重新加载对象到 tabBar 控制器中 - 对于要隐藏的视图控制器,将 hidesBottomBarWhenPushed 设置为 YES。
  2. 另一种选择是,在手机旋转时使您的视图成为窗口中唯一的视图,然后在手机旋转回来时将 tabBarController.view 放回窗口中。

希望这可以帮助到你。


嗨,感谢您的帮助。我玩了一下视图: [appDelegate.tabBarController.view removeFromSuperview]; [self.view removeFromSuperview]; [appDelegate.window addSubview:self.view]; self.view.frame = CGRectMake(0,0,480,320);它可以正常工作,但不再自动旋转(当然,我没有更改shouldAutorotate,它始终返回YES)。 - Francescu

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接