2009-07-29 13 views
7

Tengo una UIView que se muestra a la vista. Después de 2 segundos, me gustaría volver a mover la UIView fuera de la vista. ¿Cómo hago esto? He intentado el siguiente, pero no funciona :(Animación de UIView didEndSelector: ¿el método no se llama?

He fijado el NSLog, pero no parece que se está terminando y luego llamar al método loadingViewDisappear: :(

Gracias.

... 
    [UIView beginAnimations:@"AnimateIn" context:nil]; 
    [UIView setAnimationCurve: UIViewAnimationCurveEaseOut]; 
    [UIView setAnimationDuration: 0.7f]; 
    [UIView setAnimationDidStopSelector:@selector(loadingViewDisappear:finished:context:)]; 
    loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height); 
    [UIView commitAnimations]; 
} 

- (void)loadingViewDisappear:(NSString *)animationID finished:(NSNumber *) finished context:(void *) context { 
    NSLog((finished ? @"YES!" : @"NO!")); 
    if ([animationID isEqualToString:@"AnimateIn"] && finished) { 
     [UIView beginAnimations:@"AnimateOut" context:nil]; 
     [UIView setAnimationCurve: UIViewAnimationCurveEaseIn]; 
     [UIView setAnimationDelay:2.0f]; 
     [UIView setAnimationDuration: 0.7f]; 
     loadingView.frame = CGRectMake(0, 480, 320, 80); 
     [UIView commitAnimations]; 
     [loadingView removeFromSuperview]; 
    } 
} 

Respuesta

13

Es necesario configurar el delegado de animación:

[UIView beginAnimations:@"AnimateIn" context:nil]; 
[UIView setAnimationCurve: UIViewAnimationCurveEaseOut]; 
[UIView setAnimationDuration: 0.7f]; 

//Add this 
[UIView setAnimationDelegate:self]; 

[UIView setAnimationDidStopSelector:@selector(loadingViewDisappear:finished:context:)]; 
loadingView.frame = CGRectMake(rect.origin.x, rect.origin.y - 80, rect.size.width, rect.size.height); 
[UIView commitAnimations]; 
Cuestiones relacionadas