title: Force clockwise/anticlockwise rotation for a CABasicAnimation of a UIImageView
body: <p>I'm animating a pendulum which swings from 0 degrees to max 200 degrees and then back again. The problem is that if the pendulum goes over 180 degrees, it returns to 0 by the shortest route which is to continue clockwise. And I'd like it to go anticlockwise. Here's my code:
  ('right' is a boolean which is TRUE when the pendulum is swinging from left to right)</p>
  
  <pre><code> - (void)swingPendulum {
      CABasicAnimation *rotationAnimation;
      rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
      if (right) 
          rotationAnimation.toValue = [NSNumber numberWithFloat:degreesToRadians(kMax)];
      else
          rotationAnimation.toValue = [NSNumber numberWithFloat:degreesToRadians(kMin)];                               
      rotationAnimation.duration = 1.0;
      rotationAnimation.repeatCount = 1.0; 
      rotationAnimation.delegate = self;
      rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn];
      rotationAnimation.removedOnCompletion = NO;
  
      [pendulum.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];
  }
  </code></pre>
  
  <p>Any ideas how I can make this work? It's the final piece of my swingometer puzzle which is otherwise working great :D Thanks!</p>
  
  <p>Michael</p>