objective c - Gif animation from 383 .gif's -
i've created gif animation in adobe flash, wanna import in xcode put app. have 383 gif images (frames), , have written code create smoothly flow animation:
#import "viewcontroller.h" #define image_count 383 @interface viewcontroller () @end @implementation viewcontroller - (void)viewdidload { [super viewdidload]; ////////////////// // build array of images, cycling through image names (int = 0; < image_count; i++) imageview.animationimages = [[nsarray alloc]initwithobjects:[uiimage imagenamed: [nsstring stringwithformat:@"picollage00%d.gif", i]],nil]; imageview.animationrepeatcount = 5; [imageview startanimating]; // additional setup after loading view, typically nib. }
the images , images counting picollage0383.gif
in code semantic error: start image picollage000.gif
should picollage0001.gif
, shouldn't it?
changed using if-clauses , condition in 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 image picollage0001.gif (int = 1; <= 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` nsarray imageview.animationimages = [imagearray copy]; imageview.animationrepeatcount = 5; [imageview startanimating]; }
above tested code (the loop) , generates correct filenames , stores initialized uiimage
s in nsmutablearray
.
note: depending on how large gif
s might bad idea (huge memory allocations) put images in array. if slow animation should load images before need them , dealloc them after using them immediately.
Comments
Post a Comment