////VIEWCONTROLLER.M//Tom Cat////Created by Yaguangzhu on 15/7/30.//Copyright (c) 2015 Yaguangzhu. All rights reserved.//#import "ViewController.h"@interfaceViewcontroller ()-(ibaction) drink; @property (weak, nonatomic) Iboutlet Uiimageview*Imgcat;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //additional setup after loading the view, typically from a nib.}- (void) didreceivememorywarning {[Super didreceivememorywarning]; //Dispose of any resources the can be recreated.}-(ibaction) Drink {//If you are currently performing an animation this button is effective if(self.imgCat.isAnimating) {return; } Nsmutablearray*arraym =[Nsmutablearray array]; for(inti =1; i<= One; i++) {NSString*imgname = [NSString stringWithFormat:@"%02d.png", I]; //too much memory, a different wayUIImage *imagecat =[UIImage Imagenamed:imgname]; //nsstring *path = [[NSBundle mainbundle] Pathforresource:imgname Oftype:nil]; //UIImage *imagecat = [UIImage Imagewithcontentsoffile:path];[Arraym Addobject:imagecat]; } self.imgCat.animationImages=Arraym; Self.imgCat.animationDuration= self.imgcat.animationimages.count*1; [Self.imgcat startanimating]; //to save memory, let the animation run out of deferred execution[Self.imgcat performselector: @selector (setanimationimages:) Withobject:nil Afterdelay: self.imgcat.animationimages.count*1]; }@end
ios-Tom Cat