Animazione UIView didEndSelector: metodo non viene chiamato?
Domanda
Ho un UIView che viene spostato in vista. Dopo 2 secondi, vorrei spostare nuovamente l'UIView fuori dalla vista. Come faccio a fare questo? Ho provato il seguito, ma non funziona :(
Ho installato NSLog, ma non sembra che stia finendo 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];
}
}
Soluzione
Devi impostare il delegato dell'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];
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow