Uiview IOS 7隐藏选项卡问题

Uiview IOS 7隐藏选项卡问题,uiview,ios7,uitabbarcontroller,uitabbar,Uiview,Ios7,Uitabbarcontroller,Uitabbar,IOS7中的Hide tabbar显示非正式行为 当我使用 self.tabBarController.tabBar.hidden = YES; 上面的代码隐藏了选项卡栏,但我从底部查看的视图并不保持交互式 但当我在导航中按下viewController之前使用它时 someViewController.hidesBottomBarWhenPushed = YES [self.navigationController pushViewController:someViewController

IOS7中的Hide tabbar显示非正式行为

当我使用

self.tabBarController.tabBar.hidden = YES;
上面的代码隐藏了选项卡栏,但我从底部查看的视图并不保持交互式

但当我在导航中按下viewController之前使用它时

someViewController.hidesBottomBarWhenPushed = YES
[self.navigationController pushViewController:someViewController animated:YES];
它隐藏了选项卡栏,并且从底部查看也是交互式的。
但这种情况下的问题是,当我们弹出viewController时,它会在tabbar上方显示黑色条数秒钟。

我认为你们两个问题都是由于没有很好地定义/缺少
自动重新设置任务或缺少自动布局约束(无论你们使用哪个约束)

隐藏选项卡栏时,
UITabBarController
所做的是拉伸其
视图
,使其
选项卡栏
在屏幕外。所包含的视图控制器的视图应适当拉伸以使用新空间,否则将得到空白空间和/或非交互区域

编辑:

-(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];
            }
        }
    }
刚刚意识到隐藏选项卡栏不是在默认SDK中,而是在我很久以前做的一个示例中


无论如何,拉伸UtiAbbarController的视图框在我看来是“隐藏”选项卡栏(实际上将其从屏幕上移开)的最优雅的方式,因为您不必处理子视图或直接搜索选项卡栏框。

如果您想隐藏/显示视图的UtiAbbarController,请尝试以下方法:

对于隐藏选项卡栏

 - (void)hideTabBar:(UITabBarController *) tabbarcontroller
 {
     for(UIView *view in tabbarcontroller.view.subviews)
     {
        if([view isKindOfClass:[UITabBar class]])
       {
           [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
           [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
        }
     }
  }
   - (void)showTabBar:(UITabBarController *) tabbarcontroller
     {

         for(UIView *view in tabbarcontroller.view.subviews)
         {
            if([view isKindOfClass:[UITabBar class]])
            {
               [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
            }
            else
            {
               [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
            }
         }
      }
对于显示选项卡栏

 - (void)hideTabBar:(UITabBarController *) tabbarcontroller
 {
     for(UIView *view in tabbarcontroller.view.subviews)
     {
        if([view isKindOfClass:[UITabBar class]])
       {
           [view setFrame:CGRectMake(view.frame.origin.x, 480, view.frame.size.width, view.frame.size.height)];
        }
        else
        {
           [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 480)];
        }
     }
  }
   - (void)showTabBar:(UITabBarController *) tabbarcontroller
     {

         for(UIView *view in tabbarcontroller.view.subviews)
         {
            if([view isKindOfClass:[UITabBar class]])
            {
               [view setFrame:CGRectMake(view.frame.origin.x, 431, view.frame.size.width, view.frame.size.height)];
            }
            else
            {
               [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, 431)];
            }
         }
      }

也许会有帮助。

我希望你能找到解决办法。只是想确定一下,你试过了吗

 self.edgesForExtendedLayout = UIRectEdgeBottom;

使用以下代码解决您的问题

隐藏:

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

根据您的要求,在VIEW WILLEANCE和设备上使用此方法旋转,因此我已将一些用Objective-C编写的答案改写为Swift 3.0,认为它会起作用。代码如下:

func hideTabBar() {
    let tabBarControllerView = self.tabBarController?.view
    if let tabBarControllerSubviews = tabBarControllerView?.subviews {
        for view in tabBarControllerSubviews {
            if view is UITabBar {
                view.frame = CGRect(
                    x: view.frame.origin.x,
                    y: (UIScreen.main.bounds.size.height == 568 ? 568 : 480) + 20,
                    width: self.view.frame.size.width,
                    height: self.view.frame.size.height
                )
            } else {
                view.frame = CGRect(
                    x: view.frame.origin.x,
                    y: view.frame.origin.y,
                    width: self.view.frame.size.width,
                    height: UIScreen.main.bounds.size.height == 568 ? 568 : 480
                )
            }
        }
    }
}

func showTabBar() {
    let tabBarControllerView = self.tabBarController?.view
    if let tabBarControllerSubviews = tabBarControllerView?.subviews {
        for view in tabBarControllerSubviews {
            if view is UITabBar {
                view.frame = CGRect(
                    x: view.frame.origin.x,
                    y: (UIScreen.main.bounds.size.height == 568 ? 519 : 431),
                    width: self.view.frame.size.width,
                    height: self.view.frame.size.height
                )
            } else {
                view.frame = CGRect(
                    x: view.frame.origin.x,
                    y: view.frame.origin.y,
                    width: self.view.frame.size.width,
                    height: UIScreen.main.bounds.size.height == 568 ? 519 : 431
                )
            }
        }
    }
}