#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tomImageView;
@end
@implementation ViewController
//敲汤姆猫的头部。前提:一系列动画已经导入。
(IBAction)btnKnockOutonclicked:(UIButton *)sender{
[self tomImateWith:@"KnockOut" imageCount:81];
}
//汤姆戏鸟。前提:关于鸟的动画已经导入。
(IBAction)eatOnClick:(UIButton *)sender{
[self.tomImateWith:@"eat" iamgeCout:40];
}
//动画执行方法
(void)tonAnimateWith:(NSString *)fileName iamgeCount :(NSInteger )imageCout{
//0.如果创建图片数据
if (self.tomImageView.isAnimating){
return;
}
//1.首先创建图片数组
NSMutableArray *TomImages = [NSMutableArray arry] ;
for (int i=0;i<imageCout;i++){
NSString *imageName = [NSString stringWithFormat:@"%1.jpg",fileName ,i];
NSString *path = [[NSBundle mainBundle] pathForresource:imageName ofType:nil ];
UIImage *image = [UIImage imageWithContentsOfFile:path ];
[tomImages addObject:image] ;
}
//2设置动画过程
//2.1添加动画执行的图片数组
[self.tomImageView setAnimationImages:tomImages];
//2.2设置动画执行的时间
[self.tomImagesView setAnimationDuration:self.tomImageView.animationImages.cout*0.1];
//2.3设置动画执行的次数
[self.tomImagesView setAnimationRepeatCout:1];
//2.4 设置动画开始
[self.tomImagesView startAnimating] ;
//3.在动画技术之后清空数组
[self perfomSelector:@selector(setAnimationImages) withObject:nil afterDelay:self.tomImagesView.animationDuration] ;
}