#import "ViewController.h" @interface Viewcontroller () @property (weak, nonatomic) Iboutlet Uiimageview *imageview;// Definition dictionary read plist file @property (nonatomic, strong) nsdictionary *imagecountdict; @end @implementation viewcontroller//lazy Loading, Override Get Method-(Nsdictionary *) imagecountdict {if (nil = = _imagecountdict) {//Get plist path NSString *path = [[NSBundle m] Ainbundle] pathforresource:@ "Tom" oftype:@ "Plist"]; Read data in plist _imagecountdict = [Nsdictionary Dictionarywithcontentsoffile:path]; } return _imagecountdict;} -(void) viewdidload {[Super viewdidload]; Do any additional setup after loading the view, typically from a nib.} Click on the Head button-(ibaction) Didclickknock: (ID) Sender {[Self startanimationwith:@ "knockout"]; }//Click to drink Milk-(ibaction) Didclickdrink: (ID) Sender {[Self startanimationwith:@ "drink"]; }//Click Fart-(ibaction) Didclickfart: (ID) Sender {[Self startanimationwith:@ "fart"]; }//the same code into a method, the difference becomes the parameter-(void) Startanimationwith: (NSString *) ImageName {//ThroughThe key in the dictionary obtains value, which is the number of the corresponding image nsstring *countstring = [Self.imagecountdict objectforkey:imagename]; Convert to Nsinteger nsinteger count = countstring.integervalue; Determines whether the frame animation is being executed, and if it is executing, return, that is, the subsequent code will no longer execute the IF (self.imageView.isAnimating) {return; }//1. An array is required to perform the frame animation (the array elements are image objects) Nsmutablearray *imagearray = [Nsmutablearray array]; Add picture for (int i = 0; i < count; i++) {//Stitching image name NSString *tempimagename = [NSString stringwithformat:@ "% @_%02d.jpg ", Imagename,i]; Instantiate image Object//If using imagenamed: This method instantiates a picture, it caches the instanced picture, and if it is used again, it will not be re-instantiated//UIImage *image = [UIImage Imagena Med:imagenmae]; NSString *path = [[NSBundle mainbundle] Pathforresource:tempimagename Oftype:nil]; In this way to load the picture, there will be no cache UIImage *image = [UIImage Imagewithcontentsoffile:path]; Add to Array [Imagearray addobject:image]; }//Assign the array filled with the image object to ImageView self.imageView.animationImages = Imagearray; 2. Interval of Time Self.imagevieW.animationduration = 3; 3. Number of repetitions Self.imageView.animationRepeatCount = 1; 4. Start animation [Self.imageview startanimating]; Free memory//[Self.imageview Performselector: @selector (setanimationimages:) Withobject:nil AfterDelay:self.imageView . animationduration + 1];}
iOS development UI article----UI Basics Tom Cat Animation