title: xCode rotation animation speedometer
body: <p>I have a speedometer widget I have created in my app using custom animation and I am having problems getting it to animate the way I want.</p>
  
  <p>The pick animates to a particular point depending on a value that has been passed in. It ranges from 0 - 50. So if its at 50, the pick will rotate around all the way to the right, it will remain to the left hand side. I want however, at the start for the pick to always animate all the way to the right, then back down to its correct position. This is the part I am having problems with.</p>
  
  <p>For time being I have hard coded all the values just for testing purposes.</p>
  
  <p>The pick is in the centre at the start, so I need make it appear rotated to the left.</p>
  
  <pre><code>image.transform = CGAffineTransformRotate(image.transform, -0.8);
  </code></pre>
  
  <p>Then I need to animate it to the far right so I use this</p>
  
  <pre><code> [UIView animateWithDuration:2.0 delay:0 options:UIViewAnimationOptionBeginFromCurrentState
                       animations:^{
  
                           image.transform = CGAffineTransformRotate(image.transform, 1.7);
  
  
                       }
                       completion:nil]; 
  </code></pre>
  
  <p>This works fine, so when the app starts, the pick will start from the left, then rotate all the way to the right.</p>
  
  <p>The problem comes when I add this final part in</p>
  
  <p>I then need it to rotate from the right back to the point where it needs to be. For time being I have set this to the centre.</p>
  
  <pre><code> [UIView animateWithDuration:2.0 delay:2.0 options:UIViewAnimationOptionBeginFromCurrentState
                       animations:^{
  
                           image.transform = CGAffineTransformRotate(image.transform, -0.8);
  
  
                       }
                       completion:nil];
  </code></pre>
  
  <p>When the app starts, the pick starts off at the right hand side, then rotates to the centre.  It is ignoring the first part where it should be starting off rotated to the left. </p>
  
  <p>Does anyone know why this happens? Been at this for ages now and can't seem to figure it out.</p>
  
  <p>Edit: I tried sticking the final animation inside this code here</p>
  
  <pre><code>dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
  
          });
  </code></pre>
  
  <p>The pick will animate from left to right, but then it just jumps from the right to the centre point, rather than animating to the centre point :@</p>
  
  <p>Tried this:</p>
  
  <pre><code>-(void) animateToEnd : (UIImageView *)image
  {
  
      [UIView animateWithDuration:2.0 delay:0 options:UIViewAnimationOptionBeginFromCurrentState
                       animations:^{
  
                           image.transform = CGAffineTransformRotate(image.transform, 1.7);
                           image.transform = CGAffineTransformIdentity;
  
  
                       }
                       completion:nil];
  }
  -(void) animateToFinalPosition : (UIImageView *)image
  {
  
      [UIView animateWithDuration:2.0 delay:2.0 options:UIViewAnimationOptionBeginFromCurrentState
                       animations:^{
  
  
                           image.transform = CGAffineTransformRotate(image.transform, -0.8);
                 image.transform = CGAffineTransformIdentity;
  
                       }
                       completion:nil];
  }
  
  
  -(void) speedometer : (UIImageView *)image
  {
      image.transform = CGAffineTransformRotate(image_p.transform, -0.8);
  
  
  
  
     [self animateToEnd:image];
     [self animateToFinalPosition:image];
  
  
  }
  </code></pre>
  
  <p>It is ignoring the left to right animation, and just starts from the very left</p>
  
  <p>Fixed problem. Changed the animation to this</p>
  
  <pre><code>-(void) animateToEnd : (UIImageView *)image_p
  {
  
      [UIView beginAnimations:nil context:nil];
      [UIView setAnimationDuration:2.0];
      [UIView setAnimationDelegate:self];
      [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  
      image_p.transform = CGAffineTransformRotate(image_p.transform, 1.7);
  
      [UIView commitAnimations];
  
  
  }
  -(void) animateToPosition : (UIImageView *)image_p : (float)temp
  {
  
          dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 2.0 * NSEC_PER_SEC), dispatch_get_current_queue(), ^{
  
              NSLog(@"Dispatch");
              [UIView beginAnimations:nil context:nil];
              [UIView setAnimationDuration:2.0];
              [UIView setAnimationDelay:0.0];
              [UIView setAnimationDelegate:self];
              [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
  
              image_p.transform = CGAffineTransformRotate(image_p.transform, -temp);
  
              [UIView commitAnimations];
          });
  
  }
  </code></pre>
  
  <p>That block code I was using before seem to be causing the issue</p>