iOS cross-fading images easily

If you find yourself in the need of providing an elegant slideshow with image crossfading, you have several paths that you can take.

I however found a very simple and elegant bit of code that provides this functionality. All you need is an NSTimer and a selector (example only here):

- (void)changeSlide
    if(slide > 6)//an array count perhaps
        slide = 1;
    //create the string as needed, example only
    NSString *theName = [NSString stringWithFormat:@"img_%d.png", slide];
    UIImage * toImage = [UIImage imageNamed:theName];
    [UIView transitionWithView:self.view
                        self.photoViewer.image = toImage;
                    } completion:NULL];

With a single line of code you’re able to gracefully crossfade the current image with the new image. No need to create multiple UIImageViews, etc. Easy peasy and it works extremely well.

Related Posts Plugin for WordPress, Blogger...

Leave a Reply

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

five × = 25

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>