//
//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];
/*
//序列幀動(dòng)畫(huà)要播放的圖片數(shù)組
imageView.animationImages;
//序列幀動(dòng)畫(huà)的播放時(shí)長(zhǎng)
imageView.animationDuration;
//序列幀動(dòng)畫(huà)的重復(fù)次數(shù)
imageView.animationRepeatCount;
//開(kāi)始動(dòng)畫(huà)
[imageViewstartAnimating];
//結(jié)束動(dòng)畫(huà)
[imageViewstopAnimating];
//是否正在執(zhí)行動(dòng)畫(huà)
[imageViewisAnimating];
*/
}
//以下將重復(fù)代碼構(gòu)建成類(lèi)
-(void)setTomCatAnimationWithName:
(NSString*)namewithCount:(NSInteger)count
{
//判斷該動(dòng)畫(huà)是否正在執(zhí)行
if([self.tomCatViewisAnimating])
{
return;
}
//創(chuàng)建可變數(shù)組images痢站,負(fù)責(zé)存放要播放的圖片數(shù)組
NSMutableArray*images=[NSMutableArrayarray];
for(NSIntegeri=0;i
{
//根據(jù)i來(lái)加載圖片,然后添加到可變數(shù)組images里面
NSString*imageName=[NSStringstringWithFormat:@"%@_%02ld.jpg",name,i];
//根據(jù)格式化的圖片名加載圖片image
UIImage*image=[UIImageimageNamed:imageName];
//將圖片image添加到數(shù)組images中
[imagesaddObject:image];
}
//設(shè)置動(dòng)畫(huà)圖片數(shù)組
self.tomCatView.animationImages=images;
//設(shè)置動(dòng)畫(huà)時(shí)長(zhǎng)
self.tomCatView.animationDuration=count*0.075;
//設(shè)置動(dòng)畫(huà)重復(fù)次數(shù)
self.tomCatView.animationRepeatCount=1;
//開(kāi)始動(dòng)畫(huà)
[self.tomCatViewstartAnimating];
}
-(IBAction)eatBirdAction:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"eat"withCount:40];
}
-(IBAction)cymabl:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"cymbal"withCount:13];
}
-(IBAction)drink:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"drink"withCount:81];
}
-(IBAction)fart:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"fart"withCount:28];
}
-(IBAction)pie:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"pie"withCount:24];
}
-(IBAction)scratch:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"scratch"withCount:56];
}
-(IBAction)footLeft:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"footRight"withCount:30];
}
-(IBAction)rootRight:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"footLeft"withCount:30];
}
-(IBAction)stomach:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"stomach"withCount:34];
}
-(IBAction)knock:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"knockout"withCount:81];
}
-(IBAction)angry:(UIButton*)sender
{//調(diào)用剛剛的重復(fù)代碼串
[selfsetTomCatAnimationWithName:@"angry"withCount:26];
}
-(void)didReceiveMemoryWarning{
[superdidReceiveMemoryWarning];
}
@end