11

Así que aquí está lo que tengo: Un UITabBarController que maneja diferentes UIViewControllers. En uno de UIViewController estoy tratando de cambiar la vista que se muestra cuando el dispositivo gira hacia el paisaje. la parte importante es que la vista que se muestra en el paisaje debe tomar toda la pantalla ...ocultando TabBar al girar el dispositivo iPhone al paisaje

que han aplicado correctamente los métodos:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation 
- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation 

De hecho tengo mi rotación se produce correctamente, y yo mi vistas cambiadas incluso escondo la barra de estado, la barra de navegación y la barra de pestañas PERO sigo teniendo un espacio en blanco en la parte inferior de la pantalla que es el lugar del TabBar ...

Así que supongo que establecer la propiedad oculta del tabBar no es suficiente para tener la vista en toda la pantalla. Creo que hay algunas cosas que hacer en el TabBarController o incluso en MainWindow para decir algo como "no necesito TabBarController ahora". Pero no veo cómo resolver este problema adecuadamente.

Si alguien ha estado al respecto, agradecería algo de ayuda.

gracias, Sami.

Respuesta

33

Esto funcionó para mí.


- (void)viewDidLoad { 
    [super viewDidLoad];  
    previousRect = self.view.frame; 
} 

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { 
    return YES; 
} 

- (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration; 
{ 
    if(toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft || toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {  
     [self.navigationController setNavigationBarHidden:TRUE animated:FALSE]; 
     [[UIApplication sharedApplication] setStatusBarHidden:TRUE animated:FALSE]; 
    } 
    else 
    { 
     [self.navigationController setNavigationBarHidden:FALSE animated:FALSE]; 
     [[UIApplication sharedApplication] setStatusBarHidden:FALSE animated:FALSE]; 
    } 
} 

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation { 
    UIInterfaceOrientation toOrientation = self.interfaceOrientation; 

    if (self.tabBarController.view.subviews.count >= 2) 
    { 
     UIView *transView = [self.tabBarController.view.subviews objectAtIndex:0]; 
     UIView *tabBar = [self.tabBarController.view.subviews objectAtIndex:1]; 

     if(toOrientation == UIInterfaceOrientationLandscapeLeft || toOrientation == UIInterfaceOrientationLandscapeRight) {     
      transView.frame = CGRectMake(0, 0, 480, 320); 
      tabBar.hidden = TRUE; 
     } 
     else 
     {    
      transView.frame = previousRect;  
      tabBar.hidden = FALSE; 
     } 
    } 
} 

+0

Salvaste mi día ... gracias, hombre ... – Krishnabhadra

+0

+1 también para mí! –

+0

Marque como respuesta ... :) ¡Funciona!) –

0

Este código funciona bien, pero cuando la desestimación de una UIViewController que se presenta de forma modal, mi punto de vista está en la barra de estado por 20 píxeles. Mi vista está dentro de un control de navegación por lo que no lo oculto antes de la rotación.

+0

descubrí que el problema está relacionado con la barra de navegación y solo en IOS 5.Si experimenta problemas similares, simplemente oculte y muestre su barra de navegación en consecuencia en la vista que aparezca. –

1
  • La solución anterior trabajó para mí también sólo algunos pequeños cambios para iOS 6 y por encima de:
  • en iOS6 quitar la línea: "previousRect = self.view.frame;"
  • también sustituir "animados" con "withAnimation:"
  • y eliminar "transView.frame = previousRect;" desde la parte inferior (en la función else)
  • Funciona para mí de esta manera. Y muchas gracias al usuario UB.
0

que necesitaba barra de pestañas para entrar en modo de pantalla completa en la vista horizontal y yo probamos el enfoque sugerido anteriormente utilizando

transView.frame = CGRectMake(0, 0, 480, 320);

Esto resultó ser una solución hacky y plantea muchos problemas, como con ocultar y volver a mostrar la barra de estado (la vista se superpondrá con la barra de estado cuando se vuelve a mostrar después de salir de la vista de retrato). No recomendaría esto. Lo que funcionó perfectamente para mí al final fue empujar un nuevo controlador de vista que contenga la vista de paisaje y usar la delegación para reutilizar la funcionalidad del VC original.

-1

Si tiene su UITabBarController, coloque un UINavigationController dentro del mismo, entonces puede usar hideBottomBarWhenPushed (con un poco de engaño) para hacer esto.

- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

    if (toInterfaceOrientation == UIInterfaceOrientationPortrait) { 
     self.hidesBottomBarWhenPushed = NO; 
     self.navigationController.viewControllers = self.navigationController.viewControllers; 
     [self transitionToGridLayout]; 
    } 
    else { 
     self.hidesBottomBarWhenPushed = YES; 
     self.navigationController.viewControllers = self.navigationController.viewControllers; 
     [self transitionToCoverflowLayout]; 
    } 
} 

El truco es presionar el controlador de vista para que la bandera hidesBottomBarWhenPushed es recogido. Puedes usar siguiente.

self.navigationController.viewControllers = self.navigationController.viewControllers; 
0

Este enfoque está funcionando para mí:

- (void) willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration { 

    UIView *parentView = self.tabBarController.view; 
    CGRect frame = parentView.frame; 
    CGFloat windowHeight = parentView.window.frame.size.height; 

    switch (toInterfaceOrientation) { 
     case UIInterfaceOrientationLandscapeLeft: 
     case UIInterfaceOrientationLandscapeRight: 
      CGFloat tabBarHeight = self.tabBarController.tabBar.frame.size.height; 
      frame.size.height = windowHeight + tabBarHeight; 
      break; 
     default: 
      frame.size.height = windowHeight; 
      break; 
    } 

    [UIView animateWithDuration:duration animations:^{ 
     parentView.frame = frame; 
    }]; 
} 

(Sólo a prueba en iOS8.)

+0

No funciona en iPad iOS8 – Borzh

+0

Tengo este código ejecutándose en una aplicación de producción muy bien. ¿Qué estas viendo? ¿Qué versión de iOS 8? – StephenT

+0

Simulador de iOS probado, la barra de pestañas se muestra durante la rotación. Por cierto, ¿cuál es la lógica: al girar a la barra de pestañas paisaje, la altura del marco se incrementa por la altura de la ventana? – Borzh

0

Subclase su tabBarController y ocultar el TabBar cuando sea necesario:

class tabBarVC: UITabBarController { 

    override func viewWillTransitionToSize(size: CGSize, withTransitionCoordinator coordinator: UIViewControllerTransitionCoordinator) { 
     if size.height < size.width { 
      self.tabBar.hidden = true 
     } else { 
      self.tabBar.hidden = false 
     } 
    } 

} 
0

Tal vez desea utilizar este

- (void)willAnimateRotationToInterfaceOrientation:UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration 
{ 
    [super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration]; 

    __block UIView *weakTabBar = [self.tabBarController.view.subviews objectAtIndex:1]; 
    weakTabBar.alpha = 0; 
    [UIView animateWithDuration:duration 
          delay:0 
         options:UIViewAnimationOptionCurveEaseIn // slow at the beggining 
        animations:^{ 
         weakTabBar.alpha = 1; 
        } 
        completion:^(BOOL finished) { 
         weakTabBar.alpha = 1; 
        }]; 
    } 

}

Esto no oculta la barra de pestañas, pero hace que la animación de rotación más suave.

Cuestiones relacionadas