//
//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