He probado la mayoría de las soluciones sugeridas.Al final ninguno de ellos funcionó para mí.
hideTabBarWhenPushed oculta la barra de pestañas no solo para el controlador de vista que se inserta a continuación, sino para todos los controladores de vista que se insertan dentro. Para aquellos que sí quiero que vuelva a aparecer el controlador de la barra de pestañas.
La solución de Orafaelreis (ver más arriba) parecía ser la más adecuada. Pero su intento solo funcionó con estrictas orientaciones de retratos, ni siquiera para el revés. Así que tuve que arreglarlo. Esto es lo que finalmente obtuve:
#define kTabBarHeight 49 // This may be different on retina screens. Frankly, I have not yet tried.
- (void) hideTabBar:(BOOL)hide {
// fetch the app delegate
AppDelegate *delegate = [[UIApplication sharedApplication] delegate];
// get the device coordinates
CGRect bounds = [UIScreen mainScreen].bounds;
float width;
float height;
// Apparently the tab bar controller's view works with device coordinates
// and not with normal view/sub view coordinates
// Therefore the following statement works for all orientations.
width = bounds.size.width;
height = bounds.size.height;
if (hide) {
// The tab bar should be hidden too.
// Otherwise it may flickr up a moment upon rotation or
// upon return from detail view controllers.
[self.tabBarController.tabBar setHidden:YES];
// Hiding alone is not sufficient. Hiding alone would leave us with an unusable black
// bar on the bottom of the size of the tab bar.
// We need to enlarge the tab bar controller's view by the height of the tab bar.
// Doing so the tab bar, although hidden, appears just beneath the screen.
// As the tab bar controller's view works in device coordinations, we need to enlarge
// it by the tab bar height in the appropriate direction (height in portrait and width in landscape)
// and in reverse/upside down orientation we need to shift the area's origin beyond zero.
switch (delegate.tabBarController.interfaceOrientation) {
case UIInterfaceOrientationPortrait:
// Easy going. Just add the space on the bottom.
[self.tabBarController.view setFrame:CGRectMake(0,0,width,height+kTabBarHeight)];
break;
case UIInterfaceOrientationPortraitUpsideDown:
// The bottom is now up! Add the appropriate space and shift the rect's origin to y = -49
[self.tabBarController.view setFrame:CGRectMake(0,-kTabBarHeight,width,height+kTabBarHeight)];
break;
case UIInterfaceOrientationLandscapeLeft:
// Same as Portrait but add the space to the with but the height
[self.tabBarController.view setFrame:CGRectMake(0,0,width+kTabBarHeight,height)];
break;
case UIInterfaceOrientationLandscapeRight:
// Similar to Upside Down: Add the space and shift the rect. Just use x and with this time
[self.tabBarController.view setFrame:CGRectMake(0-kTabBarHeight,0,width+kTabBarHeight,height)];
break;
default:
break;
}
} else {
// reset everything to its original state.
[self.tabBarController.view setFrame:CGRectMake(0,0,width,height)];
[self.tabBarController.tabBar setHidden:NO];
}
return;
}
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation{
// It is important to call this method at all and to call it here and not in willRotateToInterfaceOrientation
// Otherwise the tab bar will re-appear.
[self hideTabBar:YES];
// You may want to re-arrange any other views according to the new orientation
// You could, of course, utilize willRotateToInterfaceOrientation instead for your subViews.
}
- (void)viewWillAppear: (BOOL)animated {
// In my app I want to hide the status bar and navigation bar too.
// You may not want to do that. If so then skip the next two lines.
self.navigationController.navigationBar.barStyle = UIBarStyleBlackTranslucent;
[[UIApplication sharedApplication] setStatusBarHidden:YES withAnimation:UIStatusBarAnimationSlide];
[self hideTabBar: YES];
// You may want to re-arrange your subviews here.
// Orientation may have changed while detail view controllers were visible.
// This method is called upon return from pushed and pulled view controllers.
return;
}
- (void)viewWillDisappear: (BOOL)animated {
// This method is called while this view controller is pulled
// or when a sub view controller is pushed and becomes visible
// Therefore the original settings for the tab bar, navigation bar and status bar need to be re-instated
[self hideTabBar:NO];
// If you did not change the appearance of the navigation and status bar in viewWillAppear,
// then you can skip the next two statements too.
self.navigationController.navigationBar.barStyle = UIBarStyleBlack;
[[UIApplication sharedApplication] setStatusBarHidden:NO withAnimation:UIStatusBarAnimationSlide];
return;
}
Los comentarios en línea deben explicar el razonamiento de cada afirmación. Sin embargo, puede haber formas más inteligentes de codificarlo.
Hay un efecto secundario junto con la ocultación de la barra de estado y la barra de navegación, que no quiero ocultarles. 1. Cuando regrese de este controlador de navegación al controlador de navegación llamante, la barra de estado y la barra de navegación del controlador llamante se superponen hasta que el dispositivo se gire una vez o hasta que la pestaña relacionada haya sido elegida nuevamente después de que haya otra pestaña al frente. 2. Cuando el controlador de vista llamante es una vista de tabla y cuando el dispositivo está en modo apaisado al volver a la mesa, la tabla se muestra con la orientación adecuada para el paisaje, pero se muestra como si fuera un retrato. La esquina superior izquierda está bien, pero algunas celdas de tabla más barra de pestañas están ocultas debajo de la pantalla. En el lado derecho hay algo de espacio libre. Esto también se soluciona al rotar el dispositivo nuevamente.
Te mantendré actualizado una vez que encontré soluciones para estos errores menores pero desagradables.
Esto es definitivamente mejor. ¡Gracias! – givp
Una cosa para recordar: debe poner el código anterior ANTES de presionarlo al controlador. Eso es justo después de la línea de inicialización. NO funcionará si pones esto en viewDidLoad o en un lugar similar ... – Lukasz
Muy bien, resolvió mis horas horas horas !!! – Rahul