Search code examples
objective-ciosanimationcore-animationslideshow

iOS Looping Image Slideshow


I have around 30 images. I want to have a slideshow running of these images without user intervention. Prime requirements are -

  1. image1 fadesIn, displays for 20 seconds, image1 fadesOut - image2 FadesIn etc. All this happens automatically. No user intervention.
  2. Also when we reach the last image, image20. The slideshow loops back to the first image.
  3. This slideshow might have other elements also like UILabel. So it's just not image slideshow.

My biggest problem is how to chain 20 images into this fadein/fadeout animation? How do we get this done in iOS?


Solution

  • You can use an UIView containing a different UIImageView for each image you have to show on your slideshow and create a nested animation block. Something like this:

    [UIView animateWithDuration:1.0 
                     animations:^{ /* animations */ } 
                     completion:^(BOOL finished){ [UIView animateWithDuration:1.0 
                                                                   animations:^{ /* animations */ } 
                                                                   completion:^(BOOL finished){ [UIView animateWithDuration:1.0 
                                                                                                                 animations:^{ /* animations */ } 
                                                                                                                 completion:^(BOOL finished){}]; }]; }];