UITabbar应用程序中的方向问题

时间:2010-11-18 11:35:00

标签: ios4 orientation uitabbar

我正在制作标签栏应用程序,其中我通过以下方式调用导航控制器 问题是我无法定向到横向模式。任何人都可以说我出错了吗?

此致 Sathish所在

-(IBAction)click


{

    tabBarController = [[UITabBarController alloc] init];

    NSMutableArray *localControllersArray = [[NSMutableArray alloc] initWithCapacity:5];

    UINavigationController *localNavigationContriller;

    FavouritesViewController *master;
    master = [[FavouritesViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:master];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
     [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [master release];

    NeedViewController *need;
    need = [[NeedViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:need];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [need release];

    DontNeedViewController *dontneed;
    dontneed = [[DontNeedViewController alloc] initWithTabBar];
    localNavigationContriller=[[UINavigationController alloc] initWithRootViewController:dontneed];
    [localNavigationContriller.navigationBar setBarStyle:UIBarStyleBlackTranslucent];
    [localControllersArray addObject:localNavigationContriller];
    //[localNavigationContriller release];
    [dontneed release];

    tabBarController.delegate=self;
    tabBarController.viewControllers = localControllersArray;
    [localControllersArray release];

    [[[UIApplication sharedApplication] keyWindow] addSubview:tabBarController.view];
}

2 个答案:

答案 0 :(得分:1)

听你说,你必须在所有标签栏中将shouldrotate功能覆盖为YES,就像你的应用程序中有3个标签栏一样,去相应的班级和

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
{
    // Return YES for supported orientations.

    return YES;
}

在标签栏的所有相应类别中...希望有帮助,如果它确实为我祈祷......

答案 1 :(得分:0)

无法更改tabBar中的一个视图的方向,而不能更改另一个视图的方向。如果指定了TabBar,则所有子视图(选项卡)必须具有相同的方向外观。您必须在每个ViewController和TabBarController中设置方向。

所以只需在所有tabbar的主控制器中添加它

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation {
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
        return YES;

    return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;
}

在你的案例中,那些要添加此代码的控制器是 FavouritesViewController, NeedViewController & DontNeedViewController