[Solved] Gif animation from 383 .gif’s [closed]


In your code is another semantic error: You start with image picollage000.gif but it should be picollage0001.gif, shouldn’t it?
I changed that using the if-clauses and another condition in the for-loop.

#import "ViewController.h"
#define IMAGE_COUNT 383

@interface ViewController ()
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    NSMutableArray *imageArray = [[NSMutableArray alloc] initWithCapacity:0];
    // Start with image picollage0001.gif
    for (int i = 1; i <= IMAGE_COUNT; i++)
        if (i < 100)
            if (i < 10)
                [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"picollage000%d.gif", i]]];
            else [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"picollage00%d.gif", i]]];
        else [imageArray addObject:[UIImage imageNamed:[NSString stringWithFormat:@"picollage0%d.gif", i]]];

    // Assuming `animationImages` is an NSArray
    imageView.animationImages = [imageArray copy];
    imageView.animationRepeatCount = 5;
    [imageView startAnimating];
}

Above is tested code (the loop) and it generates the correct filenames and stores the initialized UIImages in an NSMutableArray.

Note: Depending on how large your gifs are this might be a bad idea (huge memory allocations) to put all the images in an array. If it is a slow animation you should load the images just before you need them and dealloc them after using them immediately.

4

solved Gif animation from 383 .gif’s [closed]