iOS easy image cross fades

If you’d like to fade one UIImage to another without resorting to using two UIImageViews this following method may come in handy for you. It’s been awesome for me.

- (void)crossFadeMainImage:(UIImage *)image1 toImage:(UIImage *)image2 {
    CABasicAnimation *crossFade = [CABasicAnimation animationWithKeyPath:@"contents"];
    crossFade.duration = 0.5;
    crossFade.delegate = self;
    crossFade.fromValue = (id)image1.CGImage;
    crossFade.toValue = (id)image2.CGImage;
    [self.imageInsideScroll.layer addAnimation:crossFade forKey:@"animateContents"];
    self.imageInsideScroll.image = image2;
Related Posts Plugin for WordPress, Blogger...

2 thoughts on “iOS easy image cross fades

    1. Eric Post author

      Try it out :) Just make sure to set the image after the animation or it won’t display. For instance that

      self.imageInsideScroll.image = image2;



Leave a Reply

Your email address will not be published. Required fields are marked *

seven × = 7

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>