2009-07-29 8 views
7

J'ai un UIView qui est déplacé dans la vue. Au bout de 2 secondes, j'aimerais à nouveau faire disparaître l'UIView. Comment puis-je faire cela? Je l'ai essayé le ci-dessous, mais il ne fonctionne pas :(UIView animation didEndSelector: méthode non appelée?

J'ai installé le NSLog, mais il ne ressemble pas à ça finition, puis d'appeler la méthode loadingViewDisappear: :(

Merci.

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

Répondre

13

Vous devez définir le délégué d'animation:

[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]; 
Questions connexes