2012-01-07 18 views
7

estoy siguiendo el ejemplo de cómo crear una barra de pestañas con un botón central como Path, Instagram, etc. desde aquí: http://idevrecipes.com/2010/12/16/raised-center-tab-bar-button/botón Ocultar barra de pestañas central cuando Grupos de Vistas empujados HidesBottomBarWhenPushed

El problema que tengo es que cuando una vista se inserta en la pila que establece HidesBottomBarWhenPushed para ocultar la barra de pestañas, el botón central aún se muestra.

En los comentarios, varias otras personas han tenido este problema, pero no hay una solución de trabajo. (He intentado todas las soluciones sugeridas en los comentarios)

Se me ocurrió una solución hacky-- almacenar una referencia al botón central en una clase única no relacionada, y luego tener la vista presionada ocultar el botón cuando está cargado, y lo muestra cuando desaparece, pero esto se siente mal, y se ve raro porque puede ver el botón desaparecer antes de que comience la animación de la vista de inserción.

¿Alguien ha conseguido que esto funcione?

+0

Estoy buscando una solución a la misma, probé [self.tabBar addSubView: botón]; pero no funciona – carbonr

+0

espero que esto pueda ayudar http://stackoverflow.com/questions/11225696/how-to-hide-custom-tab-bar-button-when-hidesbottombarwhenpushed-is-true?rq=1 – vamsi575kg

Respuesta

6

Tuve el mismo problema. He editado BaseViewController.m (mi subclase UITabBarController) anulando el siguiente método viewDidLayoutSubviews (el botón es mi botón central) de la siguiente manera.

- (void)viewDidLayoutSubviews{ 
    button.center = self.tabBar.center; 
} 

Ahora su botón sigue la barra de pestañas.

+0

Remember para incluir 'button.layer.zPosition = 1;' también, para evitar que el botón esté cubierto por el tabbar – Lunayo

2

que tiene que hacer esto mismo pero con UIImageView y añadirlo a TabBar:

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:    (UIViewController *)viewController 
{ 
    if (tabBarController.selectedIndex != AUCenterTabBarButtonIntex) { 
     self.centerImageView.highlighted = NO; 
    } else { 
     self.centerImageView.highlighted = YES; 
     self.selectedIndex = AUCenterTabBarButtonIntex; 
    } 

} 


- (void)addCenterImageViewWithImage:(UIImage *)image highlitedImage:(UIImage *)highlitedImage 
{ 
    UIImageView *centerImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, image.size.width/2, image.size.height/2)]; 
    centerImageView.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin; 

    centerImageView.image = image; 
    centerImageView.highlightedImage = highlitedImage; 

    CGFloat heightDifference = centerImageView.frame.size.height - self.tabBar.frame.size.height; 
    if (heightDifference < 0) 
     centerImageView.center = CGPointMake(self.tabBar.center.x, centerImageView.center.y); 
    else 
    { 
     CGPoint center = self.tabBar.center; 
     center.y = (self.tabBar.frame.size.height/2) - (heightDifference/2); 
     centerImageView.center = center; 
    } 

    [self.tabBar addSubview:centerImageView]; 

    self.centerImageView = centerImageView; 
} 
1

Antes de empuje UIViewController, añade su botón personalizado a UITabBar

Después UIViewController pop, restaurar botón personalizado a uno mismo. Ver

Subclase UITabViewController

NSArray *array= self.viewControllers; 
for(UIViewController *controller in array){ 
if([controller isKindOfClass:[UINavigationController class]]){ 
    UINavigationController *navigationController=(UINavigationController*)controller; 
    navigationController.delegate=self; 
    } 
} 

Implementar el método de delegado

- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated { 
if (viewController.hidesBottomBarWhenPushed) { 
    CGRect rect= [button convertRect:button.bounds toView:self.tabBar]; 
    [button removeFromSuperview]; 
    [self.tabBar addSubview:button]; 
    button.frame=rect; 
} 
} 
-(void)navigationController:(nonnull UINavigationController *)navigationController didShowViewController:(nonnull UIViewController *)viewController animated:(BOOL)animated{ 
if(!viewController.hidesBottomBarWhenPushed){ 
    CGRect rect= [button convertRect:button.bounds toView:self.view]; 
    [button removeFromSuperview]; 
    [self.view addSubview:button]; 
    button.frame=rect; 
} 
} 
Cuestiones relacionadas