2015-01-21 45 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 
相關問題