1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
| #import "ViewController.h"
@interface ViewController () @property (weak, nonatomic) IBOutlet UIImageView *tom;
@end
@implementation ViewController
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view. } - (IBAction)tomAction:(UIButton *)sender { [self tomAnimationWithName:sender.currentTitle count:sender.tag]; } - (void)tomAnimationWithName:(NSString *)name count:(NSInteger)count { if([self.tom isAnimating]) return; NSMutableArray *arrayM=[NSMutableArray array]; for (int i=0; i<count; i++) { NSString *imageName=[NSString stringWithFormat:@"%@_%02d.jpg",name,i]; UIImage *image=[UIImage imageNamed:imageName]; //NSString *path=[[NSBundle mainBundle] pathForResource:imageName ofType:nil]; //UIImage *image=[UIImage imageWithContentsOfFile:path]; [arrayM addObject:image]; } //设置动画 self.tom.animationImages=arrayM; //设置重复次数 self.tom.animationRepeatCount=1; //设置动画时长 self.tom.animationDuration=self.tom.animationImages.count*0.075; //开始动画 [self.tom startAnimating]; //ji结束后释放内存 [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:self.tom.animationDuration]; } @end
|