繁体   English   中英

方向更改时隐藏UITabBar

[英]Hide an UITabBar when Orientation change

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

当我的方向改变时,我想要隐藏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并使当前视图占据其空间?


谢谢

您可以结合使用当前解决方案:

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

检测旋转。 (我认为你将它与view.transform = CGAffineTransformMakeRotation结合使其旋转......?)

我认为你可以轻松做到这两点的方法是:

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

希望这可以帮助

暂无
暂无

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

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