Pregunta

Mi aplicación tiene un UITabBarController con cinco pestañas. Que necesitaba para girar orientaciones sólo para la quinta pestaña. Yo era capaz de conseguir los cinco para girar con el paisaje subclasificando la 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];

lo que necesito ahora para desactivar la rotación de viewController1 - 4; He intentado, sin éxito, para hacer esto añadiendo el siguiente código a los cuatro archivos * .m para estos viewControllers.

- (BOOL)shouldAutorotateToInterfaceOrientation:
    (UIInterfaceOrientation)interfaceOrientation {

return NO;
}

Espero su consejo sobre cómo llegar R Listo. Gracias por leer, Marcos

¿Fue útil?

Solución

Asumo que hay otras maneras más fáciles de hacer esto, pero finalmente me dieron una solución. El título de la quinta viewController en el tabBarController, el único Eso tiene que cambiar la orientación, es "MyNotes"

Dentro de SubListViewController.m se crea el objeto TabBarControllerRotate.

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

tabBarController subclases UITabBarController e incluye una propiedad BOOL nombrar bMyNotes.

SubListViewController es un UITabBarControllerDelegate

Cada vez que la vista se cambia en el tabBarController se envía un mensaje, a saber,   - (void) tabBarController: (UITabBarController *) tabBarController       didSelectViewController: (UIViewController *) viewController

Por lo tanto SubListViewController.m contiene este código:

   #pragma mark UITabBarControllerDelegate methods

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

   }

A continuación, TabBarControllerRotate.m contiene:

    - (BOOL)shouldAutorotateToInterfaceOrientation:
          (UIInterfaceOrientation)interfaceOrientation {

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

        return ( (interfaceOrientation == UIInterfaceOrientationLandscapeRight 
            || interfaceOrientation == UIInterfaceOrientationLandscapeLeft
            || interfaceOrientation == UIInterfaceOrientationPortrait
                 ) && self.bMyNotesTab 
               );
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top