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;
    }
  • 相关阅读:
    14.使用ConfigMap管理应用配置
    13.实战交付一套dubbo微服务到k8s集群(6)之交付dubbo服务的消费者集群到K8S
    12.实战交付一套dubbo微服务到k8s集群(5)之交付dubbo-monitor到K8S集群
    11.实战交付一套dubbo微服务到k8s集群(4)之使用Jenkins进行持续构建交付dubo服务的提供者
    11.实战交付一套dubbo微服务到k8s集群(3)之dubbo微服务底包镜像制作
    10.实战交付一套dubbo微服务到k8s集群(3)之二进制安装Maven
    9.实战交付一套dubbo微服务到k8s集群(2)之Jenkins部署
    《说透中台》读书笔记
    消息队列高手课——04 | 如何利用事务消息实现分布式事务?
    消息队列高手课——03 | 消息模型:主题和队列有什么区别?
  • 原文地址:https://www.cnblogs.com/crazygeek/p/5635954.html
Copyright © 2011-2022 走看看