title: How to cancel UIView block-based animation?
body: <p>I've searched loads of SO stuff and in Apple's references, but still unable to manage my problem.</p>
  
  <h2>What I have:</h2>
  
  <ol>
  <li>A screen with 2 <code>UIImageView</code>s and 2 <code>UIButton</code>s connected to them</li>
  <li>2 kinds of animation:
  
  <ol>
  <li>Scaling up and then down of each image, one after another, only once in <code>viewDidLoad</code></li>
  <li>When a button pressed (a custom button hidden 'inside' of each <code>UIImageView</code>) it triggers animation of appropriate <code>UIImageView</code>–only one, not both–(also scale up, then down).</li>
  <li>As I am writing for iOS4+ I'm told to use block based animations!</li>
  </ol></li>
  </ol>
  
  <h2>What I need:</h2>
  
  <p>How do I cancel a running animation? I've managed to cancel after all but the last one... :/</p>
  
  <p>Here is my code snippet:</p>
  
  <pre><code>[UIImageView animateWithDuration:2.0 
                                 delay:0.1 
                               options:UIViewAnimationOptionAllowUserInteraction 
                            animations:^{
          isAnimating = YES;
          self.bigLetter.transform = CGAffineTransformScale(self.bigLetter.transform, 2.0, 2.0);
      } completion:^(BOOL finished){
          if(! finished) return;
          [UIImageView animateWithDuration:2.0 
                                     delay:0.0 
                                   options:UIViewAnimationOptionAllowUserInteraction 
                                animations:^{
              self.bigLetter.transform = CGAffineTransformScale(self.bigLetter.transform, 0.5, 0.5);
          } completion:^(BOOL finished){
              if(! finished) return;
              [UIImageView animateWithDuration:2.0 
                                         delay:0.0 
                                       options:UIViewAnimationOptionAllowUserInteraction 
                                    animations:^{
                  self.smallLetter.transform = CGAffineTransformScale(self.smallLetter.transform, 2.0, 2.0);
              } completion:^(BOOL finished){
                  if(! finished) return;
                  [UIImageView animateWithDuration:2.0 
                                             delay:0.0 
                                           options:UIViewAnimationOptionAllowUserInteraction 
                                        animations:^{
                      self.smallLetter.transform = CGAffineTransformScale(self.smallLetter.transform, 0.5, 0.5);
                  }
                                        completion:^(BOOL finished){
                                            if (!finished) return;
                                            //block letter buttons
                                            [self.bigLetterButton setUserInteractionEnabled:YES];
                                            [self.smallLetterButton setUserInteractionEnabled:YES];
                                            //NSLog(@"vieDidLoad animations finished");
                                        }];
              }];
          }];
      }];
  </code></pre>
  
  <p>Somehow the <code>smallLetter</code> <code>UIImageView</code> is not working properly, because when pressed (through button) <code>bigLetter</code> is canceling animations properly...</p>
  
  <p><strong>EDIT:</strong>
  I've used this solution, but still having problem with scaling down <code>smallLetter</code> <code>UIImageView</code> - not cancelling at all...
  <a href="https://stackoverflow.com/questions/8190197/what-is-the-best-way-to-stop-a-chain-of-block-based-animations">solution</a></p>
  
  <p><strong>EDIT2:</strong> I've added this at the beginning of next/prev methods:</p>
  
  <pre><code>- (void)stopAnimation:(UIImageView*)source {
      [UIView animateWithDuration:0.01
                            delay:0.0 
                          options:(UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction)
                       animations:^ {
                           source.transform = CGAffineTransformIdentity;
                       }
                       completion:NULL
       ];
  }
  </code></pre>
  
  <p>problem stays... :/ no idea how to interrupt last animation for letters in animation chain</p>