iOS 6中的iOS隐藏标签栏创建黑条(iOS 6的修复打破了iOS 7!) [英] iOS Hiding tab bar in iOS 6 creates black bar (fix for iOS 6 breaks iOS 7!)

查看:107
本文介绍了iOS 6中的iOS隐藏标签栏创建黑条(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 *在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)];
}
其他
{
[查看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 *在tabbarcontroller.view.subviews中查看)
{
if([view isKindOfClass:[UITabBar class]])
{
[view setFrame: CGRectMake(view.frame.origin.x,fHeight,view.frame.size.width,view.frame.size.height)];
}
其他
{
[查看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)隐藏视图:(UIView *)查看动画:(BOOL)动画
{
if(self.tabBar.hidden == hidden)
return;

CGRect screenRect = [[UIScreen mainScreen] bounds];
浮动高度= 0.0f;

if(UIDeviceOrientationIsLandscape([UIApplication sharedApplication] .statusBarOrientation))
{
height = screenRect.size.width;
}
其他
{
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完成)= ^(BOOL完成){
self.tabBar.hidden = hidden;
};

if(animated)
{
[UIView animateWithDuration:0.25f animations:workerBlock completion:completionBlock];
}
else
{
workerBlock();
completionBlock(YES);
}
}


解决方案

我最终得到了这个工作,但它花了一段时间。它源于我的原始代码和一些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];

浮动高度= 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),
宽度,
高度);

[self moveTabBarToPosition:height];
};

[UIView animateWithDuration:0.25f animations:workerBlock];
}
//在屏幕上移动标签栏及其子视图,使顶部位于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];
}
}
}

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


I've got a tabbed application and in one tab there is a UIWebView. When I rotate the device to landscape I've made the UIWebView full screen while hiding the status and tab bar.

I've got it working in iOS 6 - originally when rotating and hiding the tab bar it would leave a black space where the tab bar was, so the fHeight code fixes this. However, on iOS 6 it worked perfectly, but now it actually creates the black bar problem iOS 6 was having!! Any ideas for a workaround to this?

Please see my edit below this

- (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];
}

//Edit

I've tried using this but I'm not sure how to pass in the view properly - I've tried self.view and webView and others but I can't get it to work on both iOS 6 and 7! Any kind of idea at all would be really helpful! Let me know if you need more info

- (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);
    }
}

解决方案

I eventually got this working, but it took a while. It stemmed from a mixture of my original code and some of JRG-Developers work.

- (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];
        }
    }
}

In my case this is for my webview but theoretically you can give it any view. Works in iOS 6 and 7

这篇关于iOS 6中的iOS隐藏标签栏创建黑条(iOS 6的修复打破了iOS 7!)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆