iphone - iOS 在 iOS 6 中隐藏标签栏会创建黑条(针对 iOS 6 的修复破坏了 iOS 7!)

标签 iphone ios objective-c ipad uiwebview

我有一个选项卡式应用程序,在一个选项卡中有一个 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];
}

//编辑

我试过使用它,但我不确定如何正确传递 View - 我试过 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);
    }
}

最佳答案

我创建了一个公共(public) Gist on Github了解我们是如何做到这一点的。

由于 @Chris Byatt,此解决方案已经历多次迭代我们的团队正在尝试。因此,请确保从那里下载最新版本。

方法签名已简化为

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

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

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

关于iphone - iOS 在 iOS 6 中隐藏标签栏会创建黑条(针对 iOS 6 的修复破坏了 iOS 7!),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19006545/

相关文章:

在设备上测试时 iOS 崩溃 - 调试日志

ios - 如何通过滑动制作可拖动的 UIView?

iphone - 像google plus一样查看开关

iphone - 应用程序在某些国家/地区崩溃

ios - Y 坐标未正确更新

objective-c - 如何更改 SFSafariViewController 工具栏颜色

iphone - 通过 VPN 的内联网网站

iphone - iOS 静态库作为具有自定义构建配置的项目的子项目?

ios - 根据某些条件 swift 执行同时操作

ios - 一个文件很多的APP,如何轻松改名?