UIViewアニメーションdidEndSelector:メソッドが呼び出されていませんか?

StackOverflow https://stackoverflow.com/questions/1200122

  •  05-07-2019
  •  | 
  •  

質問

ビューに移動したUIViewがあります。 2秒後、UIViewを再びビューから外したいと思います。どうすればいいですか?私は以下を試しましたが、動作しません:(

NS

ありがとう。

...
    [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