简体   繁体   English

方向更改时隐藏UITabBar

[英]Hide an UITabBar when Orientation change

I have a quite simple question but the answer is not so easy. 我有一个非常简单的问题,但答案并不那么容易。

I want to hide a UITabBar when my orientation change. 当我的方向改变时,我想要隐藏UITabBar。

I looked 2 ways : 我看了两种方式:

Frame way 框架方式

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

Works fine but I have a blank area, so tried to play with tabBarController.view.frame et myViewController.view.frame but I didn't get any good result. 工作正常,但我有一个空白区域,所以尝试使用tabBarController.view.frame和myViewController.view.frame但我没有得到任何好结果。

Navigation Controller Way 导航控制器方式

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

Works but isn't a good solution for my app 工作,但不是我的应用程序的好解决方案

Update: 更新:

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

Works fine but doesn't autorotate anymore (and of course, I didn't change the shouldAutorotate and it always returns YES) 工作正常,但不再自动旋转(当然,我没有更改shouldAutorotate,它总是返回YES)


How can I hidde my tabBar and make the current view taking its space ? 如何隐藏我的tabBar并使当前视图占据其空间?


Thanks 谢谢

You can use the current solution combined with: 您可以结合使用当前解决方案:

[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didRotate:) name:@"UIDeviceOrientationDidChangeNotification" object:nil];

to detect rotation. 检测旋转。 (I think that you combine this with view.transform = CGAffineTransformMakeRotation to make it rotate...?) (我认为你将它与view.transform = CGAffineTransformMakeRotation结合使其旋转......?)

Two ways I think you can easily do this would be: 我认为你可以轻松做到这两点的方法是:

  1. to reload the objects back into the tabBar controller - with the hidesBottomBarWhenPushed set to YES for the viewControllers you want to be hidden. 将对象重新加载回tabBar控制器 - 将hidesBottomBarWhenPushed设置为YES,以便隐藏viewControllers。
  2. The other option would be to just make your view the only view for the window when the phone is rotated and then put the tabBarController.view back in the window when the phone is rotated back 另一种选择是在旋转手机时让你的视图成为窗口的唯一视图,然后在手机旋转回来时将tabBarController.view放回窗口

Hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM