title: iOS: CABasicAnimation and UIViewAnimation ( [UIView BeginAnimation] ) Mystery in viewDidLoad
body: <p>Normally I don't perform any animation in <code>viewDidLoad</code>.</p>
  
  <p>But for testing purposes, I tried to place and test these one by one within <code>viewDidLoad</code>:</p>
  
  <hr>
  
  <p><code>CABasicAnimation</code></p>
  
  <p><code>[UIView animateWithDuration:delay:options:animations:completion:]</code> </p>
  
  <p>and finally the now deprecated: </p>
  
  <p><code>[UIView BeginAnimation]</code> </p>
  
  <p>(which I haven't used for a long time; again, just for testing purpose in this case)</p>
  
  <hr>
  
  <p>And I experienced some thing I cannot explain for the past hours.</p>
  
  <p>In <code>viewDidLoad</code>, if I start the <code>CABasicAnimation</code>, it works - it animates.</p>
  
  <p>But if I place either: </p>
  
  <p><code>[UIView animateWithDuration:delay:options:animations:completion:]</code> or <code>[UIView BeginAnimation]</code> in <code>viewDidLoad</code>, no animation is started and instead the item will be placed at the final animated position.</p>
  
  <p>Out of curiosity, I did the following:</p>
  
  <p>I wrapped either <code>[UIView animateWithDuration:delay:options:animations:completion:]</code> or<code>[UIView BeginAnimation]</code> within:</p>
  
  <pre><code>double delayInSeconds = 0.0;
  dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
  dispatch_after(popTime, dispatch_get_main_queue(), ^(void)
  {
      //UIView animation block / [CAAnimation Begin] Animation goes here. As you can see,   
      //there is no delay here.
      //I did this out of hunches.
  });
  </code></pre>
  
  <p>again in <code>viewDidLoad</code>, then animation <strong>happens</strong>. It is not because of <code>dispatch_get_main_queue()</code> I think because I tried to log the queue before <code>dispatch_after</code> above by using:</p>
  
  <pre><code>NSLog(@"%@", [NSOperationQueue mainQueue]);
  </code></pre>
  
  <p>It is in fact on the main queue (as a matter of fact, I am not using any <code>GCD</code> at all. But just to confirm, I tried to log it this way.</p>
  
  <p><em><strong>Can anyone explain to me why</em></strong> <code>CABasicAnimation</code> works here in <code>viewDidLoad</code> and others don't. And why placing <code>UIView animation</code> block and the <code>[CAAnimation Begin]</code> within <code>dispatch_after</code> even without delay works?</p>
  
  <p>I am just testing these types of animation methods (that is my goal); so I am not doing complex animation - it is just something as simple as moving an item linearly from one point to another.</p>