2011-03-16 7 views
6

Tengo una aplicación que utiliza un UITabBarController, y tengo otra vista que debe deslizarse hacia arriba desde detrás de los controles de la barra de pestañas, pero delante del contenido de la barra de pestañas. Si eso no está claro, imagine un anuncio deslizándose en una aplicación con pestañas que aparece frente a todo, excepto por los botones de la barra de pestañas.Agregar una UIView persistente con UITabBarController

Hasta ahora he código que se ve algo como esto, pero estoy dispuesto a cambiarlo si hay una mejor manera de hacer esto ...

tabBarController.viewControllers = [NSArray arrayWithObjects:locationNavController, emergencyNavController, finderNavController, newsNavController, nil]; 

aboutView = [[AboutView alloc] initWithFrame:CGRectMake(0, window.frame.size.height - tabBarController.tabBar.frame.size.height - 37 , 
                 320, window.frame.size.height - tabBarController.tabBar.frame.size.height)]; 


[window addSubview:tabBarController.view]; // adds the tab bar's view property to the window 
[window addSubview:aboutView]; // this is the view that slides in 
[window makeKeyAndVisible]; 

Actualmente aboutView es una subclase de UIView y se sienta en su posición de inicio en la parte inferior, pero oculta el tabBarController. ¿Cómo puedo cambiar esto para permitir que las pestañas estén en la parte superior, pero aún así tener el aboutView frente al otro contenido?

Respuesta

2

Necesita agregar el aboutView como una subvista de la vista en el controlador de vista actualmente activo en el UITableBarController. Puede acceder a esa vista a través de la propiedad selectedViewController.

Puede agregar código a su implementación aboutView para animar la vista cuando aparezca.

Hago algo así en una vista emergente que quiero que aparezca debajo de los controles de la barra de pestañas. Se puede añadir un poco de código para el mensaje didMoveToSuperview sobre la aplicación aboutView:

- (void)didMoveToSuperview 
{ 
    CGRect currentFrame = self.frame; 

    // animate the frame ... this just moves the view up a 10 pixels. You will want to 
    // slide the view all the way to the top 
    CGRect targetFrame = CGRectOffset(currentFrame, 0, -10); 

    // start the animation block and set the offset 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; // animation duration in seconds 
    [UIView setAnimationDelegate:self]; 

    self.frame = targetFrame; 

    [UIView commitAnimations]; 
} 

Así que cuando se añade a su aboutView a la vista del controlador de la vista seleccionada, se anima automáticamente.

+0

impresionante. eres mi héroe – shulmey

+0

@ user663222 No hay problema :) Me alegro de que haya sido útil. – RedBlueThing

Cuestiones relacionadas