title: CABasicAnimation stop animation on completion - iOS
body: <p>I have an iOS app which is using a <code>CABasicAnimation</code> on repeat:</p>
  
  <pre><code>    CABasicAnimation *fadeAnim = [CABasicAnimation animationWithKeyPath:@"opacity"];
      fadeAnim.fromValue = [NSNumber numberWithFloat:1.0];
      fadeAnim.toValue = [NSNumber numberWithFloat:0.2];
      fadeAnim.duration = 1.0;
      fadeAnim.autoreverses = YES;
      fadeAnim.repeatCount = INFINITY;
      [colourbutton.titleLabel.layer addAnimation:fadeAnim forKey:@"opacity"];
  </code></pre>
  
  <p>I have a button which when pressed is meant to stop the animation.</p>
  
  <pre><code>-(IBAction)stopAnim {
      [colourbutton.titleLabel.layer removeAllAnimations];
  }
  </code></pre>
  
  <p>It works fine but one thing I am noticing is that is stops the animation suddenly, it doesn't let the animation finish. So how can I get it to finish the current animation and then stop. (Or in other words how can I get it to <code>removeAllAnimations....withAnimation</code>?).</p>
  
  <p>On a side note, do I need to include <code>CoreAnimation</code> framework for this to work. So far the animation is running and I havn't imported the <code>CoreAnimation</code> framework.</p>
  
  <p>Thanks, Dan.</p>