title: iOS: a Complete 360 Degree-Rotation Using Block, Not CABasicAnimation
body: <p>It should be something really simple, but I have not been successful in getting this to work using blocks. There are questions and answers to this, but all of them I found are solved by the use of <code>CABasicAnimation</code> and not by <code>UIView</code> Block-Based Animation, which is what I am after.</p>
  
  <p>The following code doesn't work (Block-Based), no animation:</p>
  
  <pre><code>CGAffineTransform spin = CGAffineTransformRotate(spiningView.transform, DEGREES_RADIANS(360));
  
  CATransform3D identity = CATransform3DIdentity;
  CATransform3D spin2 =  CATransform3DRotate(identity, DEGREES_RADIANS(360), 0.0f, 0.0f, 1.0f);
  
  
  [UIView animateWithDuration:3.0f
                        delay:0.0f
                      options:UIViewAnimationOptionCurveLinear
                   animations:^
                   {
                       spiningView.transform = spin;
                       //spiningView.layer.transform = spin2;
                       //Have also tried the above, doesn't work either.
                   }
                   completion:^(BOOL finished)
                   {
                       spiningView.transform = spin;
                       //spiningView.layer.transform = spin2;
                   }];
  </code></pre>
  
  <p>From my understanding, when every time we use Block-Based, no animation would occur, when <code>UIViewAnimation</code> Block "sees" that the begin value is the same as the final value. Fair enough, setting it to move to 360 degree would mean that the object stays where it is. But it has to be a way to use Block-Based Animation to make this animate, because the following <code>CABasicAnimation</code> would work flawlessly:</p>
  
  <pre><code>CABasicAnimation* rotationAnimation;
  rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
  rotationAnimation.fromValue = [NSNumber numberWithFloat:0.0f];
  rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0f];
  rotationAnimation.duration = 3.0f;
  rotationAnimation.cumulative = YES;
  rotationAnimation.repeatCount = 1;
  [spiningView.layer addAnimation:rotationAnimation forKey:@"rotationAnimation"];  
  </code></pre>
  
  <p>In Addition, the following Block-Based works, but there is a stop in between animations (first it rotates to 180 degrees, then therefrom to make another 180 degrees to complete the rotation), which is not what I am after:</p>
  
  <pre><code>[UIView animateWithDuration:3.0f
                        delay:0.0f
                      options:UIViewAnimationOptionCurveLinear
                   animations:^
                   {
                       spiningView.transform = CGAffineTransformRotate(spiningView.transform, DEGREES_RADIANS(180));;
                   }
                   completion:^(BOOL finished)
                   {                         
                       [UIView animateWithDuration:3.0f
                                             delay:0.0f
                                           options:UIViewAnimationOptionCurveLinear
                                        animations:^
                                        {
                                           spiningView.transform = CGAffineTransformRotate(spiningView.transform, DEGREES_RADIANS(360));
                                        }
                                        completion:^(BOOL finished)
                                        {
  
                                        }];
  
                   }];
  </code></pre>
  
  <p>I know I could save a lot of time and just surrender myself to using <code>CABasicAnimation</code> and be done with it, but I would like to <strong>know</strong> why one works and the other doesn't in this case (making a 360 degree rotation). I hope that you can give me a detailed explanation regarding this between the 2 in this case and some code (Block-Based) that can carry out a complete 360 degree rotation.</p>
  
  <p>Thanks in advance. </p>