Eventually:
BeyondViewController.h
beyondviewcontroller.h// 05_tomcat//// Created by Beyond on 14-7-23.// Copyright (c) 2014 Com.beyond. All rights reserved.//#import <UIKit/UIKit.h> @interface Beyondviewcontroller: Uiviewcontroller@property (Weak, nonatomic) Iboutlet Uiimageview *imgview_tom;-(ibaction) BtnClick: (UIButton *) sender ; @end
Beyondviewcontroller.m
beyondviewcontroller.m//05_tomcat////Created by Beyond on 14-7-23.//Copyright (c) 2014 Com.beyond. All rights reserved.//#import "BeyondViewController.h" @interface Beyondviewcontroller () {nsdictionary *_dict;} @end @implementation beyondviewcontroller-(void) viewdidload{[Super Viewdidload]; Sg_bundle template code, 1, gets the. App main package, 2, returns the FullPath full path of a file in the main package nsbundle *mainbundle = [NSBundle mainbundle]; NSString *fullpath = [Mainbundle pathforresource:@ "Tom.plist" oftype:nil]; _dict = [Nsdictionary Dictionarywithcontentsoffile:fullpath]; }-(ibaction) Btnclick: (UIButton *) Sender {//If being animated, return directly if ([_imgview_tom isanimating]) {return; }//button above the text is the dictionary key, the corresponding value-1 is the corresponding animation picture number//NSString *text = Sender.titleLabel.text; NSString *text = [Sender titleforstate:uicontrolstatenormal]; int *picnum = [_dict[text] intvalue]; NSLog (@ "%@----%d", text,picnum); Call the custom method to play the animation [self playanimatitonnamed:text picnumber:picnum]; }-(VOID) playanimatitonnamed: (NSString *) name Picnumber: (int) picnum{//Instantiate variable group Nsmutablearray *array = [Nsmutablearray ar Ray]; Add uiimage for (int i=0; i<picnum; i++) to a mutable array {//Generate image Mode 1, memory-resident, heavy pressure, real chance to collapse nsstring *fullname = [N Sstring stringwithformat:@ "%@_%02d.jpg", name,i]; UIImage *img = [UIImage imagenamed:fullname]; Generate image mode 2,io Read full path, run out, do not reside memory//nsstring *fullpath = [[NSBundle mainbundle] Pathforresource:fullname oftype:nil ]; UIImage *IMG2 = [[UIImage alloc] initwithcontentsoffile:fullpath]; Add UIImage to array [array addobject:img]; }//Set Uiimageview animation parameters and submit animation _imgview_tom.animationimages = array; _imgview_tom.animationduration = 0.1*picnum; _imgview_tom.animationrepeatcount = 1; [_imgview_tom startanimating];} @end
Ios_5_ Tom Cat