UITabbar 应用程序中的方向问题

Posted

技术标签:

【中文标题】UITabbar 应用程序中的方向问题【英文标题】:Orientation issues in UITabbar application 【发布时间】:2010-11-18 11:34:59 【问题描述】:

我正在开发标签栏应用程序,在该应用程序中我按以下方式调用导航控制器 问题是我无法定向到横向模式。谁能说说我哪里出错了?

问候, 萨蒂什

-(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];

【问题讨论】:

【参考方案1】:

听着,你必须在所有标签栏中将 shouldrotate 函数重写为 YES ,就像你的应用中有 3 个标签栏一样,转到相应的类并

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 

    // Return YES for supported orientations.

    return YES;

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

【讨论】:

【参考方案2】:

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

所以只需将它添加到所有标签栏的主控制器中

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

    return toInterfaceOrientation != UIInterfaceOrientationPortraitUpsideDown;

在您的情况下,要添加此代码的控制器是 FavouritesViewController, NeedViewController & DontNeedViewController

【讨论】:

以上是关于UITabbar 应用程序中的方向问题的主要内容,如果未能解决你的问题,请参考以下文章

如何将UITabBar嵌入故事板xcode中的另一个UITabBar

monotouch 中的自定义 uitabbar,类似于语音备忘录应用程序

快速设置UITabBar中的默认选项卡

UITabBar 中的 UICollectionView 在首次加载时显示错误的位置

iOS:如何选择 UITabBar 中的特定选项卡和此选项卡中的特定行

AppDelegate 中的 Swift UITabbar 阴影