【问题标题】:Orientation issues in UITabbar applicationUITabbar 应用程序中的方向问题
【发布时间】: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];
}

【问题讨论】:

    标签: ios4 orientation uitabbar


    【解决方案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

      【讨论】:

        猜你喜欢
        • 2011-05-14
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-03-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多