title: What is the best way to wait for a loop of UIView animations to finish?
body: <p>I'm trying to loop over multiple <code>UIViews</code> and perform animation on each, but I'd like to know when all of the animations have finished. What is the best way to call a function when the loop of animations has finished? Alternately, is there a way to wait until all have finished? </p>
  
  <p>I tried using <code>setAnimationDidStopSelector</code>, but it doesn't fire. In this case, I'm clearing some "chips" off a game board by having them fade out then get removed (NumberedChipView is a subclass of UIView). Play cannot continue until the chips are off the board.  </p>
  
  <pre><code>[UIView beginAnimations:nil context:nil]; 
  [UIView setAnimationDelegate: self];
  [UIView setAnimationDidStopSelector:@selector(animationDidStop)]; 
  
  // clear chips 
  for (HexagonalTile *aTile in tilesToClear) {
  
      NumberedChipView *chipView = [self chipViewForColumn:aTile.column andRow:aTile.row];
  
      [UIView animateWithDuration:0.5 delay:0.3 options:UIViewAnimationCurveLinear animations:^{
          chipView.alpha = 0.0; 
      } 
          completion:^(BOOL finished){
  
           if (finished) {
  
               [chipView removeFromSuperview]; 
               [self.chipViews removeObject:chipView];
  
           }
       }]; 
  }
  
  [UIView commitAnimations]; 
  </code></pre>
  
  <p>I also tried <code>CATransaction</code> to no avail: </p>
  
  <pre><code>[CATransaction begin];  
  
  [CATransaction setCompletionBlock:^{
      [self animationFinished]; 
  }];  
  
  // clear chips 
  for (HexagonalTile *aTile in tilesToClear) {
  
      NumberedChipView *chipView = [self chipViewForColumn:aTile.column andRow:aTile.row];
  
      [UIView animateWithDuration:0.5 delay:0.3 options:UIViewAnimationCurveLinear animations:^{
          chipView.alpha = 0.0; 
      } 
          completion:^(BOOL finished){
  
           if (finished) {
  
               [chipView removeFromSuperview]; 
               [self.chipViews removeObject:chipView];
  
               //NSLog(@"clearing finished"); 
           }
       }]; 
  }
  
  [CATransaction commit]; 
  </code></pre>
  
  <p><strong>Update:</strong> </p>
  
  <p>I now can get the selector to fire, however it doesn't wait for the loop of animations to finish. </p>
  
  <pre><code>[UIView setAnimationDidStopSelector:@selector(animationDidStop:finished:)];
  </code></pre>