2015-01-21 84 views
0

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

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

有什么办法可以做到以下任何一种?

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

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

回答

0

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

这个项目可以帮助你:

RDVTabBarController

此外,我必须警告你,使用自定义的TabBar控制器你可能失去了使用该系统焊接设备contrller提供了便利的功能的机会。

只有当系统tabbar控制器不符合您的需要时,才应使用自定义tabbar控制器。

0

请尝试下面的代码。这里使用的ViewController是UITabBarController的子类。在.h文件中添加ITabBarDelegate,UITabBarControllerDelegate.I以这种方式猜你可以添加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