Вопрос

У меня есть 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];
    }
}
Это было полезно?

Решение

Вам нужно установить делегата анимации:

[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];
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top