UIView动画didEndSelector:方法没被调用?

时间:2009-07-29 13:07:44

标签: iphone animation uiview

我有一个移动到视图中的UIView。 2秒后,我想再次将UIView移出视野。我该怎么做呢?我已经尝试了以下,但它不起作用:(

我已经设置了NSLog,但它看起来并没有完成,然后调用loadingViewDisappear:方法:(

谢谢。

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

1 个答案:

答案 0 :(得分:13)

您需要设置动画委托:

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