我的应用具有五个标签一个的UITabBarController。 我需要只为第五个标签旋转方向。 我能够通过继承得到所有五个旋转到横向 所述的UITabBarController

@implementation TabBarControllerRotate

-(BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation {

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

@end

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; 我没能成功做到这一点通过添加以下代码四个* .m文件为 这些viewControllers。

- (BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation {

return NO;
}

请告诉我如何获得R来。 感谢阅读,马克

有帮助吗?

解决方案

我认为还有其他更容易的方法来做到这一点,但我终于得到了一个解决方案。 第五的viewController在TabBarController,唯一的标题 需要改变方向,是“MyNotes”

内部SubListViewController.m的TabBarControllerRotate对象被创建。

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

TabBarController子类的UITabBarController并且包括BOOL属性 命名bMyNotes。

SubListViewController是UITabBarControllerDelegate

每个视图在TabBarController改变时被发送的消息,即    - (无效)tabBarController:(*的UITabBarController)tabBarController       didSelectViewController:(的UIViewController *)的viewController

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

   #pragma mark UITabBarControllerDelegate methods

   - (void)tabBarController:(UITabBarController *)tabBarController 
        didSelectViewController:(UIViewController *)viewController{
    BOOL b = (viewController.title == @"MyNotes");
    [tbc 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 
               );
}
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top