ios 7当隐藏tabbar时只在横向视图中有些空间保持黑色

时间:2013-10-10 07:48:32

标签: ios7 uitabbar

在我的应用程序纵向视图中,tabbar是show,对于横向视图,它设置为隐藏,这在ios6中顺利工作,但对于iOS7在Landscape视图中,tabbar被隐藏但其空间保持不变。按照我的代码。

-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if(![UICommonUtils isiPad]){

            if(toInterfaceOrientation == UIDeviceOrientationLandscapeRight || toInterfaceOrientation == UIDeviceOrientationLandscapeLeft) {

                [UICommonUtils hideTabBar:self.tabBarController];

            } else if(toInterfaceOrientation == UIDeviceOrientationPortrait || toInterfaceOrientation == UIDeviceOrientationPortraitUpsideDown){

                [UICommonUtils showTabBar:self.tabBarController];
            }
      }
}

隐藏标签栏

+(void)hideTabBar:(UITabBarController *)tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];

    float fHeight = screenRect.size.height;
    if(  UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width;
    }

    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)];
            view.backgroundColor = [UIColor blackColor];
        }
    }
}

显示标签栏

+(void)showTabBar:(UITabBarController *) tabbarcontroller
{
    CGRect screenRect = [[UIScreen mainScreen] bounds];
    float fHeight = screenRect.size.height - 49.0;

    if(  UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation) )
    {
        fHeight = screenRect.size.width - 49.0;
    }
    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)];
        }
    }
}

1 个答案:

答案 0 :(得分:0)

viewDidLoad方法中添加以下代码行:

if ([self respondsToSelector:@selector(edgesForExtendedLayout)]) 
{
    self.edgesForExtendedLayout = UIRectEdgeNone;
}