2012-05-02 5 views
1

내 코드에서 검사가 실행됩니다. 검사 결과가 true이면 애니메이션을 실행하고 UIAlertView를 사용자에게 표시합니다. 내 문제는 애니메이션이 완료 될 때까지 UIAlertView를 지연하는 방법을 모른다는 것입니다. 따라서 현재 UIAlertView가 표시되고 애니메이션이 백그라운드에서 실행되는 것으로 보입니다. 어떤 도움을 주셔서 감사합니다.UIAlertView에서 지연 설정

BOOL isComplete = [self checkJigsawCompleted:droppedInPlace withTag:tag]; 
     if (isComplete) { 

      [stopWatchTimer invalidate]; 
      stopWatchTimer = nil; 
      [self updateTimer]; 

      [UIView beginAnimations:nil context:nil]; 
      [UIView setAnimationDuration:1]; 
      imgGrid.alpha = 0; 
      imgBackground.alpha = 0; 
      [UIView commitAnimations]; 
      NSString *completedMessage = [NSString stringWithFormat:@"You completed the puzzle in: %@", lblStopwatch.text]; 


      UIAlertView *jigsawCompleteAlert = [[UIAlertView alloc] //show alert box with option to play or exit 
            initWithTitle: @"Congratulations!" 
            message:completedMessage 
            delegate:self 
            cancelButtonTitle:@"I'm done" 
            otherButtonTitles:@"Play again",nil]; 
      [jigsawCompleteAlert show]; 
     } 

답변

2

로 전환 blocks-based animation method에 : 당신은 단순히 당신의 애니메이션이 완료되면 대한 처리기를 추가 할 수 있습니다

if (isComplete) { 

    [stopWatchTimer invalidate]; 
    stopWatchTimer = nil; 
    [self updateTimer]; 

    [UIView animateWithDuration:1.0f animations:^{ 
     imgGrid.alpha = 0; 
     imgBackground.alpha = 0; 
    } completion:^(BOOL finished) { 
     NSString *completedMessage = [NSString stringWithFormat:@"You completed the puzzle in: %@", lblStopwatch.text]; 
     UIAlertView *jigsawCompleteAlert = [[UIAlertView alloc] //show alert box with option to play or exit 
              initWithTitle: @"Congratulations!" 
              message:completedMessage 
              delegate:self 
              cancelButtonTitle:@"I'm done" 
              otherButtonTitles:@"Play again",nil]; 
     [jigsawCompleteAlert show]; 
    }]; 
} 
+0

마찬가지로 간단합니다! 감사. '1.0f '에서'f'의 의미를 말해 줄 수 있습니까? – garethdn

+0

"f"는 플로트임을 나타냅니다. –

+0

"it 's"는 몇 초입니까? 이것이 필요하거나 좋은 연습일까요? 'f'가없는 몇 가지 예제를 보았습니다. – garethdn

1

: 물론

[UIView beginAnimations:nil context:nil]; 
[UIView setAnimationDuration:1]; 
[UIView setAnimationDelegate:self]; 
[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)]; 
... 

당신이해야, 여기에 관련 코드입니다 대화 상자를 표시하는 animationDidStop:finished:context:에 대한 구현을 제공하십시오.

beginAnimations 및 그 계열은 iOS 4.0부터 권장되지 않으며 블록 기반 애니메이션을 사용하는 것이 좋습니다. 그러나 iOS 3.x를 지원하려면 위의 내용이 문제의 해결책입니다.

관련 문제