0

我的应用程序有一个带有五个选项卡的 UITabBarController。我只需要为第五个选项卡旋转方向。通过子类化 UITabBarController,我能够让所有五个旋转到横向

@implementation TabBarControllerRotate

-(BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation {

//return (interfaceOrientation == UIInterfaceOrientationPortrait);
return (interfaceOrientation == UIInterfaceOrientationLandscapeRight 
          || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
          || interfaceOrientation == UIInterfaceOrientationPortrait);
}

@结尾

if(tbc == nil){
    //tbc = [[UITabBarController alloc] initWithNibName:nil bundle:nil];        
    tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil];  ////// new  //////

……

tbc.viewControllers = 
[NSArray arrayWithObjects:viewController1, viewController2, viewController3
 ,viewController4,viewController5, nil];

我现在需要关闭 viewController1 - 4 的旋转;我尝试通过将以下代码添加到这些 viewController 的四个 *.m 文件来执行此操作,但未成功。

- (BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation {

return NO;
}

请告诉我如何完成 R。感谢阅读,马克

4

1 回答 1

0

我认为还有其他更简单的方法可以做到这一点,但我终于找到了解决方案。TabBarController中第5个viewController的标题,唯一需要改变方向的,就是“MyNotes”

在 SubListViewController.m 内部创建了 TabBarControllerRotate 对象。

  tbc = [[TabBarControllerRotate alloc] initWithNibName:nil bundle:nil];
  tbc.viewControllers = [NSArray arrayWithObjects:viewController1
          , viewController2, viewController3, viewController4, viewController5, 无
  tbc.delegate = 自我;

TabBarController 是 UITabBarController 的子类,并包含一个 BOOL 属性名称 bMyNotes。

SubListViewController 是一个 UITabBarControllerDelegate

每次在 TabBarController 中更改视图时都会发送一条消息,即 - (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

因此 SubListViewController.m 包含以下代码:

   #pragma 标记 UITabBarControllerDelegate 方法

   - (void)tabBarController:(UITabBarController *)tabBarController
        didSelectViewController:(UIViewController *)viewController{
    BOOL b = (viewController.title == @"MyNotes");
    [待定 setBMyNotesTab:b];
    //NSLog(@"MyNotesTab == %d", [tbc bMyNotesTab]);

   }

然后 TabBarControllerRotate.m 包含:

    - (BOOL)shouldAutorotateToInterfaceOrientation:
          (UIInterfaceOrientation)interfaceOrientation {

        //NSLog(@"bMyNotesTab is: %d",self.bMyNotesTab);

        return ( (interfaceOrientation == UIInterfaceOrientationLandscapeRight
            || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
            || interfaceOrientation == UIInterfaceOrientationPortrait
                 ) && self.bMyNotesTab
               );
}
于 2009-08-28T02:12:55.420 回答