代码之家  ›  专栏  ›  技术社区  ›  Divya Bhaloidiya

ios 7当仅在横向视图中隐藏选项卡时,一些空间保持为黑色

  •  0
  • Divya Bhaloidiya  · 技术社区  · 11 年前

    在我的应用程序中,纵向视图中的选项卡被显示,横向视图中的它被设置为隐藏,这在ios6中工作很顺利,但横向视图中iOS7的选项卡被隐藏,但它的空间保持原样。下面是我的代码。

    -(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 回复  |  直到 7 年前
        1
  •  0
  •   Divya Bhaloidiya    11 年前

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

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