zoukankan      html  css  js  c++  java
  • UITabBar的隐藏

    当页面使用 UITabBarController + UINavigationController 框架的时候,当跳转到详情页面的时候,如果 UITabBar 仍然存在的话就会造成逻辑混乱,用户体验也会下降,因此我们就有一个在详情页将 UITabBar 隐藏的需求,当然,在其他的一些情况也可能有隐藏 UITabBar 的需求, 在这里小编为大家介绍三种隐藏 UITabBar 的方法,大家可以根据详细的需求进行选择。

    1、第一种:

     直接隐藏当前页面的 UITabBar

    // 显示tabBar
    self.tabBarController.tabBar.hidden = NO;
    // 隐藏tabBar
    self.tabBarController.tabBar.hidden = YES;

    2、第二种:

     将 push 到的页面的 UItabBar 隐藏

    // 在push跳转时隐藏tabBar
    UIViewController *vc2 = [UIViewController new];
    vc2.hidesBottomBarWhenPushed = YES;
    [vc1 pushViewController:vc2 animated:YES];

     该方法在push页面的时候使用,有一定的局限性,根据其名字可以发现,只有在 push跳转的时候才会生效,也就是说在 UITabBarController 和 UINavigationController 结合使用的时候能用。

     这也正是小编子在开篇时提到的那种情况,小编个人觉得也是比较常用的一种情况!

    3、第三种:

     不使用系统提供的现有方法,自定义方法,修改 TabBar 的 subview 的 frame 就行了

     原理:

      UITabBarController的subview 共有两个,一个 叫 UITabBar,就是底下的那个 Bar;另一个叫UITranstionview,就是 Bar 上面的视图。这两个 view 下面还有其他的 subview,这就不用去管它了。把UITabBar的 y 向下移49个单位,把UITranstionview 的 hight 加长 49 个单位。

     代码1:

    - (void)hidesTabBar:(BOOL)hidden{
         
         [UIView beginAnimations:nil context:NULL];
         [UIView setAnimationDuration:0];
         
         for (UIView *view in self.tabBarController.view.subviews) {
             if ([view isKindOfClass:[UITabBar class]]) {
                 if (hidden) {
                     [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height, view.frame.size.width , view.frame.size.height)];
                    
                 }else{
                     [view setFrame:CGRectMake(view.frame.origin.x, [UIScreen mainScreen].bounds.size.height - 49, view.frame.size.width, view.frame.size.height)];
                     
                 }
             }else{
                 if([view isKindOfClass:NSClassFromString(@"UITransitionView")]){
                     if (hidden) {
                         [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height)];
                         
                     }else{
                         [view setFrame:CGRectMake(view.frame.origin.x, view.frame.origin.y, view.frame.size.width, [UIScreen mainScreen].bounds.size.height - 49 )];
                        
                     }
                 }
             }
         }
         [UIView commitAnimations];
         
     }

     代码2:

    -(void)makeTabBarHidden:(BOOL)hide { // Custom code to hide TabBar
        if ( [self.tabBarController.view.subviews count] < 2 )
        {
            return;
        }
        UIView *contentView; if ( [[self.tabBarController.view.subviews objectAtIndex:0] isKindOfClass:[UITabBar class]] )
        {
            contentView = [self.tabBarController.view.subviews objectAtIndex:1];
        } else {
                contentView = [self.tabBarController.view.subviews objectAtIndex:0];
        }
        if (hide) {
            contentView.frame = self.tabBarController.view.bounds;
        } else {
                contentView.frame = CGRectMake(self.tabBarController.view.bounds.origin.x, self.tabBarController.view.bounds.origin.y,
                                               self.tabBarController.view.bounds.size.width, self.tabBarController.view.bounds.size.height -
                                               self.tabBarController.tabBar.frame.size.height);
        }
        self.tabBarController.tabBar.hidden = hide;
    }
  • 相关阅读:
    验证整数 Double 转 int 两种写法
    0 can't find referenced pointcut declarePointExpress
    nested exception is java.lang.IllegalArgumentException: Pointcut is not well-formed
    org.springframework.beans.factory.BeanDefinitionStoreException: Unexpected exception parsing XML doc
    嵌入式系统(胡威)2019年春第一次作业 参考答案
    PAT(B) 1021 个位数统计(Java)
    PAT(B) 1020 月饼(Java)
    PAT(B) 1019 数字黑洞(Java)
    PAT(B) 1018 锤子剪刀布(C:20分,Java:18分)
    PAT(B) 1017 A除以B(Java)
  • 原文地址:https://www.cnblogs.com/crazygeek/p/5635954.html
Copyright © 2011-2022 走看看