在iOS 6隐藏标签栏创build黑条(修复iOS 6中断iOS 7!)

我有一个选项卡应用程序,在一个选项卡中有一个UIWebView 。 当我旋转设备到风景时,我已经使UIWebView全屏,同时隐藏状态和标签栏。

我已经在iOS 6中工作了 – 最初旋转和隐藏标签栏时,会在标签栏留下一个黑色空间,所以fHeight代码修复了这个问题。 然而,在iOS 6上它完美的工作,但现在它实际上创造了iOS 6的黑吧问题! 任何想法解决这个问题?

请在下面看看我的编辑

 - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; { if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) { [self hideTabBar:self.tabBarController]; [[UIApplication sharedApplication] setStatusBarHidden:TRUE withAnimation:UIStatusBarAnimationSlide]; } else { [self showTabBar:self.tabBarController]; [[UIApplication sharedApplication] setStatusBarHidden:FALSE withAnimation:UIStatusBarAnimationSlide]; } } - (void) hideTabBar:(UITabBarController *) tabbarcontroller { CGRect screenRect = [[UIScreen mainScreen] bounds]; [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; float fHeight = screenRect.size.height; if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ) { fHeight = screenRect.size.width; } for(UIView *view in self.tabBarController.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; view.backgroundColor = [UIColor blackColor]; } } [UIView commitAnimations]; } - (void) showTabBar:(UITabBarController *) tabbarcontroller { CGRect screenRect = [[UIScreen mainScreen] bounds]; float fHeight = screenRect.size.height - 49.0; if( UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) ) { fHeight = screenRect.size.width - 49.0; } [UIView beginAnimations:nil context:NULL]; [UIView setAnimationDuration:0.5]; for(UIView *view in tabbarcontroller.view.subviews) { if([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, fHeight, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, fHeight)]; } } [UIView commitAnimations]; } 

//编辑

我试过使用这个,但我不知道如何正确地传递视图 – 我已经尝试self.view和webView和其他人,但我不能让它在iOS 6和7上工作! 任何一种想法都是非常有帮助的! 让我知道如果你需要更多的信息

 - (void)setTabBarHidden:(BOOL)hidden view:(UIView *)view animated:(BOOL)animated { if (self.tabBar.hidden == hidden) return; CGRect screenRect = [[UIScreen mainScreen] bounds]; float height = 0.0f; if(UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)) { height = screenRect.size.width; } else { height = screenRect.size.height; } if (!hidden) { height -= CGRectGetHeight(self.tabBar.frame); } void (^workerBlock)() = ^() { self.tabBar.frame = CGRectMake(CGRectGetMinX(self.tabBar.frame), height, CGRectGetWidth(self.tabBar.frame), CGRectGetHeight(self.tabBar.frame)); view.frame = CGRectMake(CGRectGetMinX(view.frame), CGRectGetMinY(view.frame), CGRectGetWidth(view.frame), height); }; void (^completionBlock)(BOOL finished) = ^(BOOL finished) { self.tabBar.hidden = hidden; }; if (animated) { [UIView animateWithDuration:0.25f animations:workerBlock completion:completionBlock]; } else { workerBlock(); completionBlock(YES); } } 

我已经在Github上创build了一个公共Gist,为我们如何做到这一点。

由于@Chris Byatt和我们的团队尝试了这个解决scheme已经经历了几次迭代。 所以,确保你从那里下载最新版本。

方法签名已经简化为

 - (void)setTabBarHidden:(BOOL)hidden animated:(BOOL)animated; 

你可以在你的UIViewController子类中像这样调用它:

 [self.tabBarController setTabBarHidden:YES animated:YES]; 

好吧,经过两个小时的努力,我的同事教会了我做正确的方法。 其实有一个非常简单的修复方法,我无法在网上find:

只是把:

  self.hidesBottomBarWhenPushed = YES; 

在viewController的init方法中,注释掉self.tabBar.hidden相关的代码。

我最终得到了这个工作,但花了一段时间。 它源于我的原始代码和一些JRG-Developers工作的混合。

 - (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { BOOL toLandscape = UIDeviceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation); CGRect screenRect = [[UIScreen mainScreen] bounds]; void (^workerBlock)() = ^() { [[UIApplication sharedApplication] setStatusBarHidden:toLandscape withAnimation:UIStatusBarAnimationSlide]; float height = toLandscape ? screenRect.size.width : screenRect.size.height - CGRectGetHeight(self.tabBarController.tabBar.frame); float width = toLandscape ? screenRect.size.height : screenRect.size.width; webView.frame = CGRectMake(CGRectGetMinX(webView.frame), CGRectGetMinY(webView.frame), width, height); [self moveTabBarToPosition:height]; }; [UIView animateWithDuration:0.25f animations:workerBlock]; } //Moving the tab bar and its subviews offscreen so that top is at position y -(void)moveTabBarToPosition:(int)y { self.tabBarController.tabBar.frame = CGRectMake(self.tabBarController.tabBar.frame.origin.x, y, self.tabBarController.tabBar.frame.size.width, self.tabBarController.tabBar.frame.size.height); for(UIView *view in self.tabBarController.view.subviews) { if ([view isKindOfClass:[UITabBar class]]) { [view setFrame:CGRectMake(view.frame.origin.x, y, view.frame.size.width, view.frame.size.height)]; } else { [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, y)]; view.backgroundColor = [UIColor blackColor]; } } } 

在我的情况下,这是我的web视图,但理论上你可以给它任何看法。 适用于iOS 6和7

 -(void) hideBottomTabs{ // Get the size of the main screen CGRect fullScreenRect = [[UIScreen mainScreen]bounds]; if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0){ UITabBar *bar = ((UITabBarController *)self.parentViewController).tabBarController.tabBar; fullScreenRect.size.height += ViewHeight(bar); } // Hide the tab bar ((UITabBarController *)self.parentViewController).tabBarController.tabBar.hidden = YES; // Resize and fill the screen [[((UITabBarController *)self.parentViewController).view.subviews objectAtIndex:0] setFrame:fullScreenRect]; 

}

我用这样的方式解决了我的问题。