2013-08-07 4 views
2

화면 전체에 걸쳐 소개 텍스트를 애니메이션화하는 일련의 애니메이션을 예약하려고합니다. 완료시 가장 마지막 애니메이션은 게임을 실행해야하는 게임 진드기 논리를 시작해야합니다.UIView animateWithDuration이 지연 시간을 준수하지 않음

어떤 이유로 모든 것이 즉시 발생합니다. 왜 이런 일이 일어나고 있는지, 아니면 더 나은 대안이 무엇인지 밝힐 수 있습니까?

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

답변

3

나의 제안은 이전 animateWithDuration 문장의 completion 블록에 후속 UIView 애니메이션 블록을 delay 0으로 설정하고 배치하는 것입니다 :

[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 요청이 거의 즉시 수행됩니다.

EDIT 2 : 블록에 0, 3, 5 초의 '환상'을주기 위해 delay을 편집했습니다.

+0

좋은 생각이지만 다음 애니메이션 사이의 애니메이션 지속 시간과 지연이 달라야합니다. – Chris

+0

그런 다음 각 'animateWithDuration'블록에서 원하는 지연을 수정하십시오. '지연'은 누적 될 것입니다. 블록에서 지연 시간을 1, 2 및 3 초로 설정하면 1, 3 및 6 초에 지연이 호출됩니다. – n00bProgrammer

+0

멋지게 완료되었습니다. 감사합니다. – Chris