如何旋转以编程方式创建的TabBarController

时间:2013-05-22 23:35:27

标签: ios rotation uitabbarcontroller

我以编程方式为这样的登录应用程序创建了一个TabBarController:

AppDelegate.h

@property (strong, nonatomic) UITabBarController *tabBarController;

-(void)createTabBarController;

AppDelegate.m

#import "AppDelegate.h"
#import "MenuPrincipalViewController.h"
#import "AfiliateViewController.h"
#import "ConsumoViewController.h"
#import "RecargaViewController.h"
#import "PlanesViewController.h"
#import "NavegationWebviewControllerViewController.h"
#import "Functions.h"

-(void)createTabBarController
{
    UIStoryboard *mainStoryboard;
    if ([[UIDevice currentDevice].model hasPrefix:@"iPhone"])
        mainStoryboard = [UIStoryboard storyboardWithName:@"iPhone" bundle: nil];

    else
    if ([[UIDevice currentDevice].model hasPrefix:@"iPad"])
        mainStoryboard = [UIStoryboard storyboardWithName:@"iPad" bundle: nil];

    self.tabBarController = [[UITabBarController alloc] init];

    self.tabBarController.customizableViewControllers = nil;

    MenuPrincipalViewController *principalVC    = [mainStoryboard instantiateViewControllerWithIdentifier:@"principalVC"];
    principalVC.tabBarItem.title                = @"Home";
    principalVC.tabBarItem.image                = [UIImage imageNamed:@"Home7.png"];
    principalVC.tabBarItem.tag                  = 1;
    UINavigationController *tab1Controller      = [[UINavigationController alloc] initWithRootViewController:principalVC];


    AfiliateViewController *afiliateVC          = [mainStoryboard instantiateViewControllerWithIdentifier:@"afiliateStoryBoard"];
    afiliateVC.tabBarItem.title                 = @"Afiliate";
    afiliateVC.tabBarItem.image                 = [UIImage imageNamed:@"Afiliate6.png"];
    afiliateVC.tabBarItem.tag                   = 2;
    UINavigationController *tab2Controller      = [[UINavigationController alloc] initWithRootViewController:afiliateVC];

    ConsumoViewController  *consumoVC           = [mainStoryboard instantiateViewControllerWithIdentifier:@"Consumo"];
    consumoVC.tabBarItem.title                  = @"Consumo";
    consumoVC.tabBarItem.image                  = [UIImage imageNamed:@"Grafica6.png"];
    consumoVC.tabBarItem.tag                    = 3;
    UINavigationController *tab3Controller      = [[UINavigationController alloc] initWithRootViewController:consumoVC];

    RecargaViewController  *recargaVC           = [mainStoryboard instantiateViewControllerWithIdentifier:@"recargaStoryBoard"];
    recargaVC.tabBarItem.title                  = @"Recarga";
    recargaVC.tabBarItem.image                  = [UIImage imageNamed:@"Cliente6.png"];
    recargaVC.tabBarItem.tag                    = 4;
    UINavigationController *tab4Controller      = [[UINavigationController alloc] initWithRootViewController:recargaVC];

    NavegationWebviewControllerViewController *navegacionWebVC   = [mainStoryboard instantiateViewControllerWithIdentifier:@"PagTigStoryBoard"];
    navegacionWebVC.tabBarItem.title            = @"Tigo";
    navegacionWebVC.tabBarItem.image            = [UIImage imageNamed:@"Tigotoolbar1.png"];
    navegacionWebVC.tabBarItem.tag              = 5;
    UINavigationController *tab5Controller      = [[UINavigationController alloc] initWithRootViewController:navegacionWebVC];

    self.tabBarController.viewControllers       = [NSArray arrayWithObjects: tab1Controller, tab2Controller, tab3Controller, tab4Controller, tab5Controller, nil];

    self.tabBarController.selectedIndex = 0;
    [self.tabBarController.tabBar setTintColor:(UIColorFromRGB(NavigationBarTintColor))];


    [self.window addSubview: self.tabBarController.view];
}

为了在登录后激活它,我这样称呼它:

AppDelegate *appDelegate = (AppDelegate *) [[UIApplication sharedApplication] delegate];
[appDelegate createTabBarController];

在垂直模式下一切都很好

Vertical Image01

但是当我旋转iPhone时,我得到了这个结果

Horizontal Image

Horizontal Image 2

旋转的唯一部分是状态栏,我该如何解决?我想旋转状态栏,tabBarcontroller和整个场景

0 个答案:

没有答案