title: Animate a UIView along an arc
body: <p>I wish to animate a view along an arc as shown in the image from position 1 to position 2.</p>
  
  <p><img src="https://i.stack.imgur.com/fEtQM.jpg" alt="enter image description here"></p>
  
  <p>What actually happens is that the view animation describes a full circle instead of an arc. My questions are:</p>
  
  <ol>
  <li>Should I be using <strong>CGPathAddArc</strong> or <strong>CGPathAddArcToPoint</strong> ?</li>
  <li>Do I need to use <strong>CGPathMoveToPoint</strong> to describe the initial location of the view or not?</li>
  </ol>
  
  <p>When I step through the code the CGPoints values are as I expect them to be, as are the angles.</p>
  
  <p>I use the following function to get CGPoints on a circle</p>
  
  <pre><code>CGPoint pointOnCircle(CGPoint centre, float radius, float angle)
  {
      float x = centre.x + radius * cosf(angle);
      float y = centre.y + radius * sinf(angle);
  
      return CGPointMake(x, y);
  }
  </code></pre>
  
  <p>I am using the following code and variants thereof but as yet I have not managed to crack it.</p>
  
  <pre><code>CAKeyframeAnimation *pathAnimation = [CAKeyframeAnimation animationWithKeyPath:@"position"];
  pathAnimation.calculationMode = kCAAnimationPaced;
  pathAnimation.fillMode = kCAFillModeForwards;
  pathAnimation.removedOnCompletion = NO;
  pathAnimation.duration = duration;
  pathAnimation.repeatCount = 1;
  
  CGPoint viewCenter = dynamicView.objectCenter;
  CGMutablePathRef arcPath = CGPathCreateMutable();
  //  CGPathMoveToPoint(arcPath, NULL, viewCenter.x, viewCenter.y);
  
  //work out the half way point
  float halfwayAngle = dynamicView.angle + (0.5f * self.angleIncrement);
  float fullwayAngle = dynamicView.angle + self.angleIncrement;
  CGPoint halfwayPoint = pointOnCircle(self.center, self.radius, halfwayAngle);
  CGPoint fullwayPoint = pointOnCircle(self.center, self.radius, fullwayAngle);
  
  CGPathAddArc(arcPath, NULL, halfwayPoint.x, halfwayPoint.y, self.radius, dynamicView.angle, fullwayAngle, clockwise);
  //    CGPathAddArcToPoint(arcPath, NULL, viewCenter.x, viewCenter.y, fullwayPoint.x, fullwayPoint.y, self.radius);
  
  pathAnimation.path = arcPath;
  CGPathRelease(arcPath);
  
  [dynamicView.layer addAnimation:pathAnimation forKey:@"arc"];
  </code></pre>