Pregunta

tengo un UITabBarController donde el controlador de vista predeterminado es un UINavigationController.Quiero poder ocultar la UITabBar del UITabBarController cuando presiono una determinada vista en el UINavigationController.

Intenté agregar:

delegate.tabBarController.hidesBottomBarWhenPushed = YES;

en mi UINavigationController antes de impulsar la vista, pero eso no parece funcionar.

¿Algún consejo sobre lo que debería hacer o si es posible?¡Gracias de antemano!

¿Fue útil?

Solución

Esto es mejor:

viewController.hidesBottomBarWhenPushed = YES;
[self.navigationController pushViewController:viewController animated:YES];

Usted tiene que fijar hidesBottomBarWhenPushed = SI en el controlador que se va a empujar a la vista ...

Otros consejos

cuando se trabaja con guión gráfico es fácil de controlador de vista de configuración que ocultar la barra de pestañas de empuje, en el controlador de vista de destino simplemente seleccione esta casilla:
introducir descripción de la imagen aquí

He encontrar la manera de conseguir esto resuelto, yo estaba corriendo en el mismo tema, pero Apple también nos dice cómo hacerlo en la muestra denominada: "Los elementos" ( http://developer.apple.com/library/ios/#samplecode/TheElements/Introduction/Intro. html )

Vea a continuación en función de cómo hacerlo, añadir esto a la función init de la vista que desea empuje!

-(id) init { 
    if(self = [super init]) { 
        self.hidesBottomBarWhenPushed = YES; 
    } 
    return self; 
}

Se ocultará automáticamente la barra de pestañas, como la aplicación de fotos hace en su iPhone. Y cuando se desplaza hacia atrás la vista padre se acaba de mostrar la barra de pestañas de nuevo.

Buena suerte

He probado la mayoría de las soluciones sugeridas. Al final ninguno de ellos trabajó para mí.

hideTabBarWhenPushed oculta la barra de pestañas no sólo para el controlador de vista que se empuja siguiente, pero para todos los controladores de vista que son empujados dentro. Para aquellos que quería volver a aparecer el controlador de la barra de pestañas.

solución Orafaelreis' (véase más arriba) parecía que la mayoría de baño. Pero su intento sólo funcionó durante estrictas orientaciones vertical, ni siquiera por al revés. Así que tuve que arreglarla. Esto es lo que finalmente me dieron:

#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;
}

La línea en los comentarios deben explicar el razonamiento para cada declaración. Sin embargo, puede haber formas más inteligentes de codificación de ella.

Hay un efecto secundario en conjunción con ocultar la barra de navegación barra de estado y también, lo que no quiero ocultar de vosotros. 1. Al regresar de este controlador de navegación para el control de navegación llamando a continuación, la barra de estado y la barra de navegación a la superposición controlador de llamada hasta que el dispositivo se gira una vez o hasta que la lengüeta relacionado ha sido elegida de nuevo después de otra pestaña llegó a frente. 2. Cuando el controlador de vista de llamada es una vista de tabla y cuando el dispositivo está en modo de paisaje cuando volver a la mesa, entonces la tabla se muestra en la orientación apropiada para el paisaje pero se presentarán como si se tratara de retrato. La esquina superior izquierda está bien, pero algunas celdas de la tabla, además de la barra de pestañas están ocultas debajo de la pantalla. En el lado derecho hay algo de espacio libre. Esto, también, es fijado por de nuevo girando el dispositivo.

Los mantendré informado una vez que encontré soluciones para estos errores menores, pero desagradables.

Así es como haces que esto funcione:

En el Application Delegate tu creas el UITabBarController.Luego creas un UINavigationController con su controlador raíz como el controlador de vista que desea en la pestaña en particular.Luego inserte el UINavigationController en el "verControladores"matriz de la UITabBarController.al igual que:

ViewControllerForTab1 *tab1Controller = [[ViewControllerForTab1 alloc] initWithNibName:@"ViewControllerForTab1"];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:tab1Controller];

[tab1Controller release];


UITabBarController *tabBarController = [[UITabBarController alloc] init];
tabBarController.viewControllers = [NSArray arrayWithObjects: navController, nil];

[navController release];


[self.window addSubView:tabBarController.view];

De esta manera puedes configurar el "hidesBottomBarWhenPushed"propiedad de"YES" en cualquier controlador de vista dentro de eso UINavigationController y ocultará el UITabBar.

¡Espero que ayude!

Te dejaré aquí mi solución para esto:

#define FRAME_HIDDEN CGRectMake(0, 0, 768, 1073) //1073 = 1024 (screen) + 49 (UITabBar) 
#define FRAME_APPEAR CGRectMake(0, 0, 768,1024)

-(void) setHidden: (BOOL) hidden{
    CGRect frame = (hidden)? FRAME_HIDDEN : FRAME_APPEAR;
    [self.tabBarController.view setFrame:frame];
    [self.tabBarController.tabBar setHidden:hidden];
}

llama al método 'setHidden' donde lo necesite! Me usar este y el 'patrón Singleton', entonces mis subvistas pueden ocultar la UITabBar en su Superview

Resulta que si se establece el punto de vista hidesBottomBarWhenPushed:YES que oculta la barra cuando la vista aparece (duh por mi parte). Estaba asignarlo al UITabBarController, lo cual no tiene mucho sentido cuando se piensa en ello.

[self.view hidesBottomBarWhenPushed:YES];
[super pushViewController:viewController animated:animated];

en la primera UIViewController "FirstItemViewController"

 @IBAction func pushToControllerAction(sender: AnyObject) {
     self.hidesBottomBarWhenPushed = true
     self.performSegueWithIdentifier("nextController", sender: self)
 }

en la siguiente UIViewController "ExampleViewController" `

 override func willMoveToParentViewController(parent: UIViewController?) {
         if parent == nil {
             var viewControllers = self.navigationController!.viewControllers
             if ((viewControllers[viewControllers.count - 2]).isKindOfClass(FirstItemViewController.self)) {
                 (viewControllers[viewControllers.count - 2] as! FirstItemViewController).hidesBottomBarWhenPushed = false
             }
         }
 }

Mira esta respuesta https://stackoverflow.com/a/36148064/3078925

Utilice hidesBottomBarWhenPushed en el controlador que desea ocultar.

Para ocultar todos los controladores de poner en prepare for segue

override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
    segue.destination.hidesBottomBarWhenPushed = true
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top