2009-07-29 21 views
7

Ho un UIView che viene spostato in vista. Dopo 2 secondi, mi piacerebbe spostare di nuovo l'UIView fuori dalla vista. Come faccio a fare questo? Ho provato il basso, ma non funziona :(Animazione UIView didEndSelector: il metodo non viene chiamato?

Ho installato il NSLog, ma non sembra che è terminato e quindi chiamando il metodo loadingViewDisappear: :(

Grazie.

... 
    [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]; 
    } 
} 

risposta

13

è necessario impostare il delegato di animazione:

[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]; 
Problemi correlati