【问题标题】:How to keep the tab bar hidden while switching between more than 5 tabs如何在超过 5 个标签之间切换时保持标签栏隐藏
【发布时间】:2015-01-21 00:38:51
【问题描述】:

我有一个 UITabBarController 作为我的应用程序的根视图控制器。它有 6 个选项卡,但该应用程序有一个自定义弹出视图,其中有 6 个按钮用于选择每个选项卡。标签栏本身始终处于隐藏状态。

问题是,一旦我尝试以编程方式选择索引 5 或 6 处的选项卡,我就会遇到问题。选项卡 1-4 很好,它们在代码中被选中,新的视图控制器出现在屏幕上。但由于标签 5 和 6 在技术上位于“更多”标签中,标签栏会短暂出现,显示动画以选择“更多”标签,然后再次消失。这也将这些“额外”视图控制器放在一个新的导航控制器中,其中“更多”表视图作为根视图控制器。这会添加一个新的导航栏并导致其他问题。

有什么方法可以做以下任何事情吗?

  1. 标签栏中有 5 个以上的标签,但没有“更多”标签。
  2. 禁用“更多”标签栏选择动画和添加关联的导航控制器。
  3. 创建一个可以完全替换 UITabBarController 的简单自定义控制器。

似乎在很多情况下,人们想要显示超过 5 个选项卡并隐藏选项卡栏,但我找不到任何人讨论这个问题。

【问题讨论】:

    标签: ios xcode uitabbarcontroller uitabbar


    【解决方案1】:

    根据您的要求,我认为您需要一个自定义的tabar控制器。

    这个项目可以帮助你:

    RDVTabBarController

    此外,我必须警告您,使用自定义选项卡控制器可能会失去使用系统选项卡控制器提供的便捷功能的机会。

    只有当系统标签栏控制器不适合您的需要时,您才应该使用自定义标签栏控制器。

    【讨论】:

      【解决方案2】:

      试试下面的代码。这里使用的 ViewController 是 UITabBarController 的子类。在 .h 文件中添加 ITabBarDelegate , UITabBarControllerDelegate。我猜这样你可以添加 6 个选项卡。我在这里完成了两个选项卡并使用动画进行了过渡。使用委托方法

      • (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController

      如下图应用动画。

      #import "ViewController.h"
      
      @interface ViewController ()
      
      @end
      
      @implementation ViewController
      
      - (void)viewDidLoad {
          [super viewDidLoad];
          fvcontroller = [self.storyboard instantiateViewControllerWithIdentifier:@"navcontroller"];
          svcontroller = [self.storyboard instantiateViewControllerWithIdentifier:@"SecondViewController"];
          NSMutableArray *viewcontrollers = [[NSMutableArray alloc]init];
          [viewcontrollers addObject:fvcontroller];
          [viewcontrollers addObject:svcontroller];
      
      
          [self setViewControllers:viewcontrollers];
      
          fvcontroller.tabBarItem = [[UITabBarItem alloc]initWithTitle:@"Me" image:[UIImage imageNamed:@"me.png"] tag:1];
          svcontroller.tabBarItem =  [[UITabBarItem alloc]initWithTitle:@"Chat" image:[UIImage imageNamed:@"chat3.png"] tag:2];
          // _tbbar.delegate = self;
          self.delegate = self;
      
      }
      
      - (void)didReceiveMemoryWarning {
          [super didReceiveMemoryWarning];
      
      }
      
      
      - (BOOL)tabBarController:(UITabBarController *)tabBarController shouldSelectViewController:(UIViewController *)viewController
      {
          UIView *from = self.selectedViewController.view;
          UIView *to = viewController.view;
          NSInteger fromindex = [self.viewControllers indexOfObject:self.selectedViewController];
          NSInteger toindex = [self.viewControllers indexOfObject:viewController];
      
          [UIView transitionFromView:from
                              toView:to
                            duration:.5
                             options:UIViewAnimationOptionTransitionFlipFromBottom
                          completion:^(BOOL finished) {
                              if (finished) {
                                  tabBarController.selectedIndex = toindex;
                              }
                          }];
      
       //(toindex > fromindex ? UIViewAnimationOptionTransitionCurlUp : UIViewAnimationOptionTransitionCurlDown)
      
          return NO;
      }
      @end
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2013-09-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-05-27
        • 1970-01-01
        相关资源
        最近更新 更多