[英]UIView animateWithDuration not respecting delay
我想安排一系列動畫,以動畫形式在屏幕上介紹文字。 最后的動畫在完成時應觸發應該運行游戲的游戲滴答邏輯。
由於某種原因,所有事情都會立即發生。 誰能闡明為什么會這樣或有更好的選擇?
[self.view bringSubviewToFront:_ViewIntroSeconds];
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
[_IntroLabel1 setAlpha:1];
}
completion:^(BOOL finished){
}];
[UIView animateWithDuration:0.4 delay:3.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
[_IntroLabel2 setAlpha:1];
[_IntroLabel1 setAlpha:0];
[_IntroLabel1 setCenter:CGPointMake(0, _IntroLabel1.center.y)];
}
completion:^(BOOL finished){
}];
[UIView animateWithDuration:0.4 delay:5.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
[_IntroLabel3 setAlpha:1];
[_IntroLabel2 setAlpha:0];
[_IntroLabel2 setCenter:CGPointMake(0, _IntroLabel2.center.y)];
}
completion:^(BOOL finished){
[self updateGame];
[self updateClock];
[_ViewIntroSeconds setAlpha:0];
}];
我的建議是將delay
設置為0,然后將后續的UIView
動畫塊放置在之前的animateWithDuration
語句的completion
塊中:
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
[_IntroLabel1 setAlpha:1];
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.4 delay:2.6 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
[_IntroLabel2 setAlpha:1];
[_IntroLabel1 setAlpha:0];
[_IntroLabel1 setCenter:CGPointMake(0, _IntroLabel1.center.y)];
}
completion:^(BOOL finished){
[UIView animateWithDuration:0.4 delay:1.6 options:UIViewAnimationOptionCurveEaseInOut
animations:^(void) {
[_IntroLabel3 setAlpha:1];
[_IntroLabel2 setAlpha:0];
[_IntroLabel2 setCenter:CGPointMake(0, _IntroLabel2.center.y)];
}
completion:^(BOOL finished){
[self updateGame];
[self updateClock];
[_ViewIntroSeconds setAlpha:0];
}];
}];
}];
這將給您想要的效果。
編輯:發生這種情況的原因是, UIView animateWithDuration
塊開始動畫,並繼續執行以下代碼,而動畫仍然有效。 因此,建議在完成塊中執行“下一個”動畫效果。 否則,將幾乎立即執行所有animateWithDuration
請求。
編輯2:我已經編輯了塊中的delay
,分別為您提供了0、3和5秒的“錯覺”。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.