yjviewcontroller.m//04-Tom Cat's understanding////Created by Jacky-mac on 15-5-31.//Copyright (c) 2015 www.train.com. All rights reserved.//#import "YJViewController.h" @interface Yjviewcontroller () @property (weak, nonatomic) Iboutlet Uiimageview *tom; @end @implementation yjviewcontroller-(void) Tomanimationwithname: (NSString *) name AndCount: ( Nsinteger) count{if ([Self.tom isanimating]) return; Number of animated pictures nsmutablearray *arraym = [Nsmutablearray array]; Add an animated picture for (int i=0; i<count; i++) {//image name NSString *imagename = [NSString Strin gwithformat:@ "%@_%02d.jpg", name,i]; NSString *path = [[NSBundle mainbundle] Pathforresource:imagename Oftype:nil]; UIImage *image = [UIImage Imagewithcontentsoffile:path]; [Arraym Addobject:image]; }//Set animation array self.tom.animationImages = Arraym; Repeat 1 times self.tom.animationRepeatCount = 1; Animation Duration Self.tom.animationDuration = Self.tom.animationImages.count * 0.075; Start animation [Self.tom startanimating]; After the animation "ends", clean up the animated array [Self.tom performselector: @selector (setanimationimages:) Withobject:nil Afterdelay : Self.tom.animationDuration]; }/*-(ibaction) tomaction: (UIButton *) sender{//Currenttitle can take out the current caption text of the button [self tomAnimationWithName:sender.cur Renttitle AndCount:sender.tag];} */-(ibaction) knockout{[self tomanimationwithname:@ "knockout" andcount:81];} -(ibaction) eat{[self tomanimationwithname:@ "eat" andcount:40];} -(ibaction) cymbal{[self tomanimationwithname:@ "cymbal" andcount:12];} -(ibaction) drink{[self tomanimationwithname:@ "drink" andcount:80];} -(ibaction) fart{[self tomanimationwithname:@ "fart" andcount:27];} -(ibaction) pie{[self tomanimationwithname:@ "pie" andcount:23];} -(ibaction) scratch{[self tomanimationwithname:@ "Scratch" andcount:55];} -(ibaction) stomach{[self tomanimationwithname:@ "stomach" andcount:34];} - (ibaction) footleft{[self tomanimationwithname:@ "footleft" andcount:30];} -(ibaction) footright{[self tomanimationwithname:@ "footright" andcount:30];} @end
iOS Learning-Tom Cat