title: iOS - CATransition issue: showing end image at start
body: <p>In my <code>UIViewController</code> I create <code>CALayer</code> with image1.</p>
  
  <pre><code>CALayer *imageLayer = [CALayer layer];
  [imageLayer setBounds:CGRectMake(0.0, 0.0, 241.0, 430.0)];
  [imageLayer setPosition:CGPointMake(160.0, 60.0)];
  [imageLayer setAnchorPoint:CGPointMake(0.5, 0.0)];
  [imageLayer setContents:(id)[UIImage imageNamed:@"image1.png".CGImage];
  [imageLayer setContentsGravity:kCAGravityResizeAspect];
  [self.view.layer addSublayer:imageLayer];
  </code></pre>
  
  <p>Later in <code>UIViewController</code> I want to change image by pushing it using <code>CATransition</code>.</p>
  
  <pre><code>CATransition *t = [CATransition animation];
  t.beginTime = [self.view.layer convertTime:CACurrentMediaTime() + 6.5 fromLayer:nil];
  t.type = kCATransitionPush;
  t.subtype = kCATransitionFromRight;
  [imageLayer setContents:(id)[UIImage imageNamed:@"image2.png"].CGImage];    
  [imageLayer addAnimation:t forKey:nil];
  </code></pre>
  
  <p>When running the code I get image2 from the beginning, transition works though by pushing itself after 6.5 seconds. 
  Where's the image1? What's wrong? </p>
  
  <p><strong>Correct answer:</strong>
  Thanks both Jacky Boy and Tiago Almeida.
  I corrected the code removing the line</p>
  
  <pre><code>t.beginTime = [self.view.layer convertTime:CACurrentMediaTime() + 6.5 fromLayer:nil];
  </code></pre>
  
  <p>and adding 'dispatch_after'.</p>
  
  <p>Now it works:</p>
  
  <pre><code>CATransition *t = [CATransition animation];
  t.type = kCATransitionPush;
  t.subtype = kCATransitionFromRight;
  [imageLayer setContents:(id)[UIImage imageNamed:@"image2.png"].CGImage];    
  [imageLayer addAnimation:t forKey:nil];
  [CATransaction begin];
  NSTimeInterval delayInSeconds = 6.5;
  dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
  dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
      [imageLayer setContents:(id)[UIImage imageNamed:@"image2.png"].CGImage];
      [imageLayer addAnimation:t forKey:nil];
  });
  [CATransaction commit];
  </code></pre>
  
  <p>Thanks again, guys!</p>