2012-02-22 11 views
8

Duplicar posibles:
Show activity indicator during application launchAdición de un indicador de actividad mediante programación a una vista

Todo,

Dentro de mi aplicación delegado, he creado una vista de bienvenida de animación que utiliza mi defecto .png. Todo funciona bien, pero no puedo entender cómo mostrar mi ActivityIndicator en la parte superior de la vista de bienvenida. Está allí simplemente oculto por la vista de bienvenida. Aquí es lo que tengo y gracias:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
//... data access stuff here ... 

self.window.rootViewController = self.tabBarController; 
[self.window makeKeyAndVisible]; 

// ... more setup stuff here ... 



/**************************************************************************** 
* 
* 
* Splash Screen for iPhone 
* 
****************************************************************************/ 
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) { 


    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)]; 
    splashView.image = [UIImage imageNamed:@"Default.png"]; 
    [self.window addSubview:splashView]; 
    [self.window bringSubviewToFront:splashView]; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:0.5]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:self.window cache:YES]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)]; 
    splashView.alpha = 0.0; 
    splashView.frame = CGRectMake(-60, -60, 440, 600); 
    [UIView commitAnimations]; 


    //Create and add the Activity Indicator to splashView 
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge]; 
    activityIndicator.alpha = 1.0; 
    activityIndicator.center = CGPointMake(160, 240); 
    activityIndicator.hidesWhenStopped = NO; 
    [splashView addSubview:activityIndicator]; 
    [activityIndicator startAnimating]; 



} 


    return YES; 
} 

Respuesta

22

Para todos aquellos que necesitaban esto, y sé que no eran muchos ...
(Hecho en Xcode versión 4.2.1)

Así que ...

En el AppDelegate.h añadir lo siguiente:

@property (nonatomic, strong) UIImageView *splashView; 

En AppDelegate.m agregue esto:

En la parte superior de la página de cours @synthesize splashView;
Y luego:

- (void) splashFade 
{ 
    splashView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0, 320, 480)]; 
    splashView.image = [UIImage imageNamed:@"Default.png"]; 
    [_window addSubview:splashView]; 
    [_window bringSubviewToFront:splashView]; 
    [UIView beginAnimations:nil context:nil]; 
    [UIView setAnimationDuration:2.0]; 
    [UIView setAnimationDelay:2.5]; 
    [UIView setAnimationTransition:UIViewAnimationTransitionNone forView:_window cache:YES]; 
    [UIView setAnimationDelegate:self]; 
    [UIView setAnimationDidStopSelector:@selector(startupAnimationDone:finished:context:)]; 
    splashView.alpha = 0.0; 
    [UIView commitAnimations]; 

    //Create and add the Activity Indicator to splashView 
    UIActivityIndicatorView *activityIndicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhite]; 
    activityIndicator.alpha = 1.0; 
    activityIndicator.center = CGPointMake(160, 360); 
    activityIndicator.hidesWhenStopped = NO; 
    [splashView addSubview:activityIndicator]; 
    [activityIndicator startAnimating]; 
} 

- (void)startupAnimationDone:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 
{ 
    [splashView removeFromSuperview]; 
} 

El [UIView setAnimationDelay: 2,5] es responsable de la duración de la splashView se encuentra al frente por el tiempo de retardo a elegir.

Se puede cambiar la posición del indicador cambiando los nubmers de x/y en:
activityIndicator.center = CGPointMake (160, 360);

Por fin, bajo la méthode:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 

Sólo añadir lo siguiente:

[self performSelector:@selector(splashFade) withObject:nil]; 

y hay que ir :)
espero que ayudó.

tenga un buen programación ....

+0

Hola, ¿cuál debería ser el parámetro en el (void) startupAnimationDone: (NSString *) animationID terminado: (NSNumber *) finalizó el contexto: (void *) context – morroko

+0

hidesWhenStopped = NO era clave para mí, de lo contrario estaría oculto sin importar qué – noobular

0

parece que esconde (alfa -> 0.0) en su splashView 0,5 seg. ¿Qué deberías ver en este caso?

+0

Sí, eso me da una buena transición de splashView a la vista principal. Cuando lo comento, sigo obteniendo el mismo resultado: el ActivityIndicator está oculto detrás de splashView – Slinky

0

Ha intentado:

[splashView bringSubviewToFront:activityIndicator]; 
+0

Sí. Obtenga el mismo resultado. El problema puede ser que splashView es un UIImageView. Escuché que a veces poner subViews encima de UIImageViews no funciona – Slinky

Cuestiones relacionadas