将iPhone设备旋转到横向时隐藏TabBar
所以这就是我所拥有的:
处理不同UIViewControllers的UITabBarController。在其中一个UIViewController中,我试图在设备旋转到横向时切换正在显示的视图。
重要的一点是景观中显示的视图必须占据整个屏幕...
So here is what i have: A UITabBarController that handles different UIViewControllers. In one of the UIViewController i am trying to switch the view being displayed when the device rotates to landscape. the important part is that the view displayed in landscape MUST take the whole screen...
我已经正确实现了这些方法:
I have correctly implemented the methods :
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
实际上我的旋转确实正确,我的意见sw。了一下。
i甚至隐藏状态栏,导航栏和标签栏我仍然在屏幕底部有一个空白区域,这是TabBar的位置......
In fact i do have my rotation occurring correctly, and I my views swaped. i even hide status bar, nav bar and Tab bar BUT i keep having a blank space at the bottom of the screen which is the place of the TabBar...
所以我假设设置tabBar的隐藏属性是不够的,以便在整个屏幕上显示视图。我认为在TabBarController甚至MainWindow中都有一些事情可以说我现在不需要TabBarController。但是我没有看到如何正确解决这个问题。
So i am assuming that setting the hidden property of the tabBar is not enough in order to have the view on the whole screen. I think there is some stuff to do within the TabBarController or even the MainWindow to say somehting like "i don't need TabBarController now". But i do not see how to get around this problem properly.
如果有人遇到过这个问题,我将不胜感激。
If anyone has been around this issue, i would appreciate some help.
谢谢你,
萨米。
thank you, Sami.
这对我有用。
- (void)viewDidLoad {
[super viewDidLoad];
previousRect = self.view.frame;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return YES;
}
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;
{
if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
[self.navigationController setNavigationBarHidden:TRUE animated:FALSE];
[[UIApplication sharedApplication] setStatusBarHidden:TRUE animated:FALSE];
}
else
{
[self.navigationController setNavigationBarHidden:FALSE animated:FALSE];
[[UIApplication sharedApplication] setStatusBarHidden:FALSE animated:FALSE];
}
}
-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
UIInterfaceOrientation toOrientation = self.interfaceOrientation;
if ( self.tabBarController.view.subviews.count >= 2 )
{
UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0];
UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1];
if(toOrientation == UIInterfaceOrientationLandscapeLeft || toOrientation == UIInterfaceOrientationLandscapeRight) {
transView.frame = CGRectMake(0, 0, 480, 320 );
tabBar.hidden = TRUE;
}
else
{
transView.frame = previousRect;
tabBar.hidden = FALSE;
}
}
}