//
//ViewController.m
//TOMCAT
//
//CreatedbyADONIS16/7/12.
//Copyright© 2016年LESSON2.Allrightsreserved.
//
#import"ViewController.h"
@interfaceViewController()
@property(weak,nonatomic)IBOutletUIImageView*tomCatView;
@end
@implementationViewController
-(void)viewDidLoad{
[superviewDidLoad];
UIImageView*imageView= [UIImageViewnew];
/*
//序列帧动画要播放的图片数组
imageView.animationImages;
//序列帧动画的播放时长
imageView.animationDuration;
//序列帧动画的重复次数
imageView.animationRepeatCount;
//开始动画
[imageViewstartAnimating];
//结束动画
[imageViewstopAnimating];
//是否正在执行动画
[imageViewisAnimating];
*/
}
//以下将重复代码构建成类
-(void)setTomCatAnimationWithName:
(NSString*)namewithCount:(NSInteger)count
{
//判断该动画是否正在执行
if([self.tomCatViewisAnimating])
{
return;
}
//创建可变数组images,负责存放要播放的图片数组
NSMutableArray*images=[NSMutableArrayarray];
for(NSIntegeri=0;i
{
//根据i来加载图片,然后添加到可变数组images里面
NSString*imageName=[NSStringstringWithFormat:@"%@_%02ld.jpg",name,i];
//根据格式化的图片名加载图片image
UIImage*image=[UIImageimageNamed:imageName];
//将图片image添加到数组images中
[imagesaddObject:image];
}
//设置动画图片数组
self.tomCatView.animationImages=images;
//设置动画时长
self.tomCatView.animationDuration=count*0.075;
//设置动画重复次数
self.tomCatView.animationRepeatCount=1;
//开始动画
[self.tomCatViewstartAnimating];
}
-(IBAction)eatBirdAction:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"eat"withCount:40];
}
-(IBAction)cymabl:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"cymbal"withCount:13];
}
-(IBAction)drink:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"drink"withCount:81];
}
-(IBAction)fart:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"fart"withCount:28];
}
-(IBAction)pie:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"pie"withCount:24];
}
-(IBAction)scratch:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"scratch"withCount:56];
}
-(IBAction)footLeft:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"footRight"withCount:30];
}
-(IBAction)rootRight:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"footLeft"withCount:30];
}
-(IBAction)stomach:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"stomach"withCount:34];
}
-(IBAction)knock:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"knockout"withCount:81];
}
-(IBAction)angry:(UIButton*)sender
{//调用刚刚的重复代码串
[selfsetTomCatAnimationWithName:@"angry"withCount:26];
}
-(void)didReceiveMemoryWarning{
[superdidReceiveMemoryWarning];
}
@end