////VIEWCONTROLLER.M//TomCat////Created by Xiaomoge on 14/12/10.//Copyright (c) 2014 Xiaomoge. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller () {UIButton*_btndrink;//Drink action ButtonUIButton *_btneat;//Eat action buttonUIButton *_btnfart;//Fart action ButtonUIButton *_btnpie;//Pie action ButtonUIButton *_btnscratch;//Grab action ButtonUIButton *_btncymbal;//Cymbals action ButtonUIButton *_btnknockout;//action button for tapping the headUIButton *_btnfootleft;//left foot action buttonUIButton *_btnfootright;//Right foot action buttonUIButton *_btnstomach;//Abdominal action ButtonUiimageview *_imageview;//Image}@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; UIImage*image = [UIImage imagenamed:@"drink_00.jpg"]; _imageview= [[Uiimageview alloc] Initwithframe:cgrectmake (0,0, the,480)]; _imageview.image=image; [Self.view Addsubview:_imageview]; _btnknockout= [Self Creatbtn:cgrectmake ( -, the, the, the) Andimage:nil Andsel: @selector (knockout)]; _btnstomach= [Self Creatbtn:cgrectmake ( -,310, -, -) Andimage:nil Andsel: @selector (stomach)]; _btnfootleft= [Self Creatbtn:cgrectmake ( the, the, +, -) Andimage:nil Andsel: @selector (footleft)]; _btnfootright= [Self Creatbtn:cgrectmake ( the,420, -, -) Andimage:nil Andsel: @selector (footright)]; _btndrink= [Self Creatbtn:cgrectmake ( -, -, -, -) Andimage:[uiimage imagenamed:@"Drink"] Andsel: @selector (drink)]; _btneat= [Self Creatbtn:cgrectmake ( -, the, -, -) Andimage:[uiimage imagenamed:@"Eat"] Andsel: @selector (Eat)]; _btnfart= [Self Creatbtn:cgrectmake ( -,260, -, -) Andimage:[uiimage imagenamed:@"fart"] Andsel: @selector (fart)]; _btnpie= [Self Creatbtn:cgrectmake ( -,260, -, -) Andimage:[uiimage imagenamed:@"Pie"] Andsel: @selector (PIE)]; _btncymbal= [Self Creatbtn:cgrectmake ( -, the, -, -) Andimage:[uiimage imagenamed:@"Cymbal"] Andsel: @selector (cymbal)]; _btnscratch= [Self Creatbtn:cgrectmake ( -, -, -, -) Andimage:[uiimage imagenamed:@"Scratch"] Andsel: @selector (Scratch)];}#pragmaMark-Create a button-(UIButton *) CREATBTN: (CGRect) Fram Andimage: (UIImage *) Image Andsel: (SEL) sel{UIButton*BTN =[[UIButton alloc] init]; Btn.frame=Fram; [Btn Setbackgroundimage:image Forstate:uicontrolstatenormal]; [Btn addtarget:self Action:sel forcontrolevents:uicontroleventtouchupinside]; [Self.view ADDSUBVIEW:BTN]; returnbtn;}#pragmaMark-performing an animated event-(void) Animationofaction: (NSString *) name Andcount: (nsinteger) count{if(_imageview.isanimating)return;//determine if the animation is being performed, and if so, whether to exit directly, or to execute the next sentenceNsmutablearray *images = [Nsmutablearray arraywithcapacity:count];//Create an array of pictures to receive the frame animations that need to be performed for(intindex =0; Index < count; index++) {NSString*imagesname = [NSString stringWithFormat:@"%@_%02d", Name,index];//generate picture names based on indexNSString *path = [[NSBundle mainbundle] pathforresource:imagesname ofType:@"jpg"];//get the path where the picture is located//Create a picture//imagenamed with cache, images created through imagenamed are placed in the cache, memory is too high when performing animations, so images created with imagenamed are not recommended for memory optimization//when you put the picture on the images.xcassets, you can only load it through imagenamed .//UIImage *image = [UIImage imagenamed:imagesname];UIImage *image = [UIImage Imagewithcontentsoffile:path];//get the picture from the path of the picture, where the path to the picture is placed under supporting files[Images Addobject:image];//add a picture to an array of frame animations} [_imageview setanimationimages:images];//set up an array of pictures that perform frame animations_imageview.animationduration = Count *0.05;//time the frame animation was executed_imageview.animationrepeatcount =1;//number of times the frame animation was executed[_imageview startanimating];//Start Animation[_imageview performselector: @selector (setanimationimages:) Withobject:nil afterdelay:_imageview.animationduration +1];//clear the cached picture after 1 seconds after the frame animation has finished executing}#pragmaMark-Belly-(void) stomach{[self animationofaction:@"Stomach"Andcount: the];}#pragmaMark-Left foot-(void) footleft{[self animationofaction:@"Footleft"Andcount: -];}#pragmaMark-Right foot-(void) footright{[self animationofaction:@"Footright"Andcount: -];}#pragmaMark-Knock head-(void) knockout{[self animationofaction:@"Knockout"Andcount:Bayi];}#pragmaMark-Water-(void) drink{[self animationofaction:@"Drink"Andcount:Bayi];}#pragmaMark-Eat-(void) eat{[self animationofaction:@"Eat"Andcount: the];}#pragmaMark-Fart-(void) fart{[self animationofaction:@"fart"Andcount: -];}#pragmaMark-Pies-(void) pie{[self animationofaction:@"Pie"Andcount: -];}#pragmaMark-Catch-(void) scratch{[self animationofaction:@"Scratch"Andcount: About];}#pragmaMark-Cymbal-(void) cymbal{[self animationofaction:@"Cymbal"Andcount: -];}@end
UI basics-Handwritten code implements Tom Cat animation