1 //2 //VIEWCONTROLLER.M3 //091215TomCat4 //5 //Created by Longma on 15/9/12.6 //Copyright (c) 2015 Dast. All rights reserved.7 //8 9 #import "ViewController.h"Ten One @interfaceViewcontroller () A-(ibaction) knockdown; -@property (Weak, nonatomic) Iboutlet Uiimageview *Imgview; --(ibaction) drink; the /** - * Response code for different times after refactoring - * - * @param the front part of the name picture + * @param len variable array length: number of pictures - */ +- (void) Catactionwithfrontname: (nsstring*) name AAndlength: (int) Len; at - @end - - @implementationViewcontroller - -- (void) Viewdidload in { - [Super Viewdidload]; to + } --(ibaction) Knockdown the { *[Self Catactionwithfrontname:@"Knockout_"Andlength: the]; $ }Panax Notoginseng - the-(ibaction) Drink + { A[Self Catactionwithfrontname:@"Drink_"Andlength: the]; the + } - $- (void) Catactionwithfrontname: (nsstring*) name $Andlength: (int) Len - { - //second, to prevent the animation from being interrupted by other time, add theif(self.imgView.isAnimating) - {Wuyireturn;//running does not respond to click events, just jump out of the way. the } - Wu //One, the realization animation (1. The animated array is a Picture object 2. Set the number of plays and durations before starting the animation) and extract the duplicate code - //1. Prepare an array of UIImage objects AboutNsmutablearray *arr =[Nsmutablearray array]; $ - for(inti =0; i < Len; i++) - { -//Stitching file name ANSString *str = [NSString stringWithFormat:@"%@%02d.jpg", name, I]; +//Convert to UIImage object the - //Three, Memory overlay problem: Imagenamed method will cache the picture, so instead of getting from the file: $ //Note at this time two points: 1. Non-PNG format to move to supporting files (drag to brown folder is successful) the //2. Add the type suffix to the file name in the code, theNSString *path = [[NSBundle mainbundle] Pathforresource:str Oftype:nil];//I can't believe I forgot. theUIImage *img =[UIImage Imagewithcontentsoffile:path]; the - //find a picture by file name and convert it to a picture object in //UIImage *img = [UIImage imagenamed:str]; the //object joins a temporary array of UIImage objects the [arr addobject:img]; About } the//Assigning a temporary mutable array to an array of UIImage objects for animation the //all of them are prepared for this step. theSelf.imgView.animationImages =arr; + -//set and start animation the[Self.imgview Setanimationrepeatcount:1];Bayi[Self.imgview SetAnimationDuration:arr.count *0.08]; the [Self.imgview startanimating]; the //Iv. releasing memory at the end of the animation - //self.imgView.animationImages = nil;//Error! The program loop mechanism, which needs to be set for a time delay before execution: - the //Note: 1.perform [email protected] 3.set+ array name + colon the [Self.imgview performselector: @selector (setanimationimages:) Withobject:nil theAfterDelay:arr.count *0.08+1]; the } - @end
Simple Tom Cat Code implementation