views:

797

answers:

1

I have a UIView that is moved into view. After 2 seconds, I'd like to move the UIView out of view again. How do I do this? I have tried the below, but it doesn't work :(

I have setup the NSLog, but it doesn't look like it's finishing and then calling the loadingViewDisappear: method :(

Thank you.

...
    [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];
    }
}
+3  A: 

You need to set the animation delegate:

[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];
Louis Gerbarg