title: How to crossfade between 2 images on iPhone using Core Animation
body: <p>I'm doing this to learn how to work with Core Animation animatable properties on iPhone (not to learn how to crossfade images, per se).</p>
  
  <p>Reading similar questions on SO leads me to believe it can be done by animating the <strong>.contents</strong> property of the <strong>UIImageView's</strong> <strong>layer</strong> like so:</p>
  
  <pre><code>UIImage *image1 = [UIImage imageNamed:@"someImage1.png"];
  UIImage *image2 = [UIImage imageNamed:@"someImage2.png"];
  
  self.imageView.image = image1;
  [self.view addSubview:self.imageView];
  
  CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@"contents"];
  crossFade.duration = 5.0;
  self.imageView.layer.contents = image2;
  [self.imageView.layer addAnimation:crossFade forKey:@"animateContents"];
  </code></pre>
  
  <p>Did I get a detail wrong or is this not possible. </p>
  
  <p><strong>Update:</strong> the above code produces a blank UIImageView. When I change this line:</p>
  
  <pre><code>self.imageView.layer.contents = image2.CGImage;
  </code></pre>
  
  <p>...I can see the image now but it does not fade in, it just appears instantly.</p>