title: iPhone Wait For Animation Ending
body: <p>In an iPhone application, I try to catch animation endings using setAnimationDidStopSelector. I try to suspend code execution until animation ends. I have tried this; set a global BOOL variable, set it to TRUE before commiting animation and after commiting animations waited using a while loop. In the setAnimationDidStopSelector, set the BOOL variable to FALSE and hope while loop to break. But unluckily this did not work, the code did not even fall into setAnimationDidStopSelector (I check that with some trace outputs). EDIT: If that BOOL variable handling is not added, code runs into the handler method.</p>
  
  <p>The code where animation takes place is below:</p>
  
  <pre><code>self.AnimationEnded=FALSE;
  [UIView beginAnimations:NULL context:NULL];
  [UIView setAnimationDuration:2];
  [UIView setAnimationDelegate:self];
  [UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:context:)];
  // do sth.
  [UIView commitAnimations];
  while(![self AnimationEnded]);
  </code></pre>
  
  <p>Also this is the code of handler:</p>
  
  <pre><code>- (void)animationDidStop:(NSString*)animationID finished:(NSNumber*)finished context:(void*)context {
      printf("abc\n"); fflush(stdout);
      self.AnimationEnded=true;
  }
  </code></pre>
  
  <p>What do you suggest?</p>