mjviewcontroller.m//03-tom////Created by Apple on 13-11-24.//Copyright (c) 2013 itcast. All rights reserved.//#import "MJViewController.h" @interface Mjviewcontroller () {nsdictionary *_dict;//Save the number of all pictures}@e Nd@implementation mjviewcontroller-(void) viewdidload {[Super viewdidload]; 1. Obtain the full path of the tom.plist nsbundle *bundle = [NSBundle mainbundle]; NSString *path = [Bundle pathforresource:@ "Tom" oftype:@ "Plist"]; 2. Load the dictionary according to the file path _dict = [Nsdictionary dictionarywithcontentsoffile:path];} -(void) Playanim: (int) Count Fliename: (NSString *) filename {//1. Create variable array nsmutablearray *images = [Nsmutablearray arr AY]; 2. Add picture for (int i = 0; i<count; i++) {//Picture name nsstring *name = [NSString stringwithformat:@]%@_%02d . jpg ", filename, I]; Full path NSString *path = [[NSBundle mainbundle] Pathforresource:name Oftype:nil]; Load picture (cache)//UIImage *img = [UIImage imagenamed:name]; No cache UIImage *img = [[UIImage alloc] initwithcontentsoffile:path]; [Images addobject:img]; }//3. Set animated picture (in order) _tom.animationimages = images;//sequence frame animation//4. Play only once _tom.animationrepeatcount = 1; 5. Set the duration of the animation _tom.animationduration = 0.1 * count; 5. Start the animation [_tom startanimating];} #pragma mark listens to all button clicks-(ibaction) Btnclick: (UIButton *) Sender {//1. If Tom is playing the animation, return directly to the IF (_tom.isanimating) return; 2. Remove the button text nsstring *title = [Sender titleforstate:uicontrolstatenormal]; 3. Get the number of images int count = [_dict[title] intvalue]; 4. Play the animation [self Playanim:count fliename:title];} @end
IOS Tom Cat Code