IOS暑假小學期實訓(xùn) 第4天 “TomCat游戲應(yīng)用程序”

2016/07/12

//

一、


// ?ViewController.m

// ?TomCat

// ?Created by lanou on 16/7/12.

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController


- (IBAction)eatBirdAction:(UIButton *)sender {

// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

? ? ?NSMutableArray *images = [NSMutableArray array];

? ?for (NSInteger i = 0;i < 40;i ++) {

// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

? ? ? ?NSString *imageName = [NSString stringWithFormat:@"eat_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

? ? ? ?UIImage *image = [UIImage imageNamed: imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

? ? ? ?[images addObject:image];

? ?}

// ? ?設(shè)置動畫圖片數(shù)組

? ?self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

? ?self.tomcatView.animationDuration = 40*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

? ?self.tomcatView.animationRepeatCount = 1;

// ? ? 開始動畫

? ?[self.tomcatView startAnimating];

}


- (IBAction)tomCatScratch:(UIButton *)sender {

// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

NSMutableArray *images = [NSMutableArray array];

? ?for (NSInteger i = 0;i < 55;i ++) {

// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

? ? ? ?NSString *imageName = [NSString stringWithFormat:@"scratch_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

? ? ? ?UIImage *image = [UIImage imageNamed: imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

? ? ? ?[images addObject:image];

? ?}

// ? ?設(shè)置動畫圖片數(shù)組

? ?self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

? ?self.tomcatView.animationDuration = 55*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

? ?self.tomcatView.animationRepeatCount = 1;

// ? ?開始動畫

? ?[self.tomcatView startAnimating];

}


- (IBAction)tomCatFootLeft:(UIButton *)sender {

//// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

? ? ?NSMutableArray *images = [NSMutableArray array];

? ?for (NSInteger i = 0;i < 30;i ++) {

? ? ? ?// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

? ? ? ?NSString *imageName = [NSString stringWithFormat:@"footLeft_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

? ? ? ?UIImage *image = [UIImage imageNamed: imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

? ? ? ?[images addObject:image];

? ?}

// ? ?設(shè)置動畫圖片數(shù)組

? ?self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

? ?self.tomcatView.animationDuration = 30*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

? ?self.tomcatView.animationRepeatCount = 1;

// ? ?開始動畫

? ?[self.tomcatView startAnimating];

}

- (IBAction)tomCatFootRight:(UIButton *)sender {

// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

NSMutableArray *images = [NSMutableArray array];

for (NSInteger i = 0;i < 30;i ++) {

// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

NSString *imageName = [NSString stringWithFormat:@"footRight_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

UIImage *image = [UIImage imageNamed: imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

[images addObject:image];

}

// ? ?設(shè)置動畫圖片數(shù)組

self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

self.tomcatView.animationDuration = 30*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

self.tomcatView.animationRepeatCount = 1;

// ? ?開始動畫

[self.tomcatView startAnimating];

}

- (IBAction)tomCatFart:(UIButton *)sender {

// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

? ?NSMutableArray *images = [NSMutableArray array];

? ?for (NSInteger i = 0;i < 27;i ++) {

? ? ? ?// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

? ? ? ?NSString *imageName = [NSString stringWithFormat:@"fart_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

? ? ? ?UIImage *image = [UIImage imageNamed: imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

? ? ? ?[images addObject:image];

? ?}

// ? ?設(shè)置動畫圖片數(shù)組

? ?self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

? ?self.tomcatView.animationDuration = 27*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

? ?self.tomcatView.animationRepeatCount = 1;

// ? ?開始動畫

? ?[self.tomcatView startAnimating];

}


- (IBAction)tomCatCymbal:(UIButton *)sender {

// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

? ?NSMutableArray *images = [NSMutableArray array];

? ?for (NSInteger i = 0;i < 12;i ++) {

? ? ? ?// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

? ? ? ?NSString *imageName = [NSString stringWithFormat:@"cymbal_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

? ? ? ?UIImage *image = [UIImage imageNamed: imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

? ? ? ?[images addObject:image];

? ?}

// ? ?設(shè)置動畫圖片數(shù)組

? ?self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

? ?self.tomcatView.animationDuration = 12*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

? ?self.tomcatView.animationRepeatCount = 1;

// ? ?開始動畫

? ?[self.tomcatView startAnimating];

}

- (IBAction)tomCatDrink:(UIButton *)sender {

// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

? ?NSMutableArray *images = [NSMutableArray array];

? ?for (NSInteger i = 0;i < 80;i ++) {

? ? ? ?// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

? ? ? ?NSString *imageName = [NSString stringWithFormat:@"drink_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

? ? ?UIImage *image = [UIImage imageNamed:imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

? ? ? ?[images addObject:image];

? }

// ? ?設(shè)置動畫圖片數(shù)組

? ?self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

? self.tomcatView.animationDuration = 80*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

? ?self.tomcatView.animationRepeatCount = 1;

// ? ?開始動畫

? ?[self.tomcatView startAnimating];

}

- (IBAction)tomCatPlain:(UIButton *)sender {

// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

? ?NSMutableArray *images = [NSMutableArray array];

? ?for (NSInteger i = 0;i < 23;i ++) {

? ? ? ?// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

? ? ? ?NSString *imageName = [NSString stringWithFormat:@"pie_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

? ? ? ?UIImage *image = [UIImage imageNamed: imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

? ? ? ?[images addObject:image];

? ?}

// ? ?設(shè)置動畫圖片數(shù)組

? ?self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

? ?self.tomcatView.animationDuration = 23*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

? ?self.tomcatView.animationRepeatCount = 1;

// ? ?開始動畫

? ?[self.tomcatView startAnimating];

}

- (IBAction)tomCatStomach:(UIButton *)sender {

// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

? ? ? NSMutableArray *images = [NSMutableArray array];

? ?for (NSInteger i = 0;i < 33;i ++) {

? ? ? ?// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

? ? ? ?NSString *imageName = [NSString stringWithFormat:@"stomach_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

? ? ? ?UIImage *image = [UIImage imageNamed: imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

? ? ? ?[images addObject:image];

? ?}

// ? ?設(shè)置動畫圖片數(shù)組

? ?self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

? ?self.tomcatView.animationDuration = 33*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

? ?self.tomcatView.animationRepeatCount = 1;

// ? ?開始動畫

? ?[self.tomcatView startAnimating];

}

- (IBAction)tomCatKnockout:(UIButton *)sender {

// ? ?創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

? ?NSMutableArray *images = [NSMutableArray array];

? ?for (NSInteger i = 0;i < 80;i ++) {

? ? ? ?// ? ? ? ?根據(jù)i 來加載圖片,然后添加到可變數(shù)組images 里面

// ? ? ? ?格式化創(chuàng)建字符串

? ? ? ?NSString *imageName = [NSString stringWithFormat:@"knockout_%02ld.jpg",i];

// ? ? ? ?根據(jù)格式化的圖片名加載圖片image

? ? ? ?UIImage *image = [UIImage imageNamed: imageName];

// ? ? ? ?將圖片image添加到數(shù)組images中

? ? ? ?[images addObject:image];

? ?}

// ? ?設(shè)置動畫圖片數(shù)組

? ?self.tomcatView.animationImages = images;

// ? ?設(shè)置動畫時長

? ?self.tomcatView.animationDuration = 80*0.075;

// ? ?設(shè)置動畫重復(fù)次數(shù)

? ?self.tomcatView.animationRepeatCount = 1;

// ? ?開始動畫

? ?[self.tomcatView startAnimating];

}

- (void)didReceiveMemoryWarning {

[super didReceiveMemoryWarning];

// Dispose of any resources that can be recreated.

}

@end

二、序列幀動畫

//

//ViewController.m

//TomCat

//

//Created bylanou on 16/7/12.

//Copyright ?2016年yhy. All rights reserved.

//

#import"ViewController.h"

@interfaceViewController()

@property(weak,nonatomic)IBOutletUIImageView*tomcatView;

@end

@implementationViewController

//UIImageView提供了一個序列幀動畫

- (void)viewDidLoad {

[superviewDidLoad];

UIImageView*imageView = [UIImageViewnew];

//序列幀動畫要播放的圖片數(shù)組

//imageView.animationImages

//序列幀動畫時長

//imageView.animationDuration

//重復(fù)次數(shù)

//imageView.animationRepeatCount

//開始動畫

//[imageView startAnimating];

//結(jié)束動畫

//[imageview stopAnimating];

//是否正在執(zhí)行動畫

//[imageView isAnimating];

-(void)tomCatAnimationWithName:(NSString*)name WithCount:(NSInteger)count{

if([self.tomcatViewisAnimating]) {

return;

}

//創(chuàng)建可變數(shù)組images,負責存放要播放的圖片數(shù)組

NSMutableArray*images = [NSMutableArrayarray];

for(NSIntegeri =0;i < count;i ++) {

//根據(jù)i來加載圖片,然后添加到可變數(shù)組images里面

//格式化創(chuàng)建字符串

NSString*imageName = [NSStringstringWithFormat:@"%@_%02ld.jpg",name,i];

//根據(jù)格式化的圖片名加載圖片image

UIImage*image = [UIImageimageNamed: imageName];

//將圖片image添加到數(shù)組images中

[imagesaddObject:image];

}

//設(shè)置動畫圖片數(shù)組

self.tomcatView.animationImages= images;

//設(shè)置動畫時長

self.tomcatView.animationDuration= count*0.075;

//設(shè)置動畫重復(fù)次數(shù)

self.tomcatView.animationRepeatCount=1;

//開始動畫

[self.tomcatViewstartAnimating];

}

- (IBAction)eatBirdAction:(id)sender {

[selftomCatAnimationWithName:@"eat"WithCount:40];

}

- (IBAction)tomCatScratch:(id)sender {

[selftomCatAnimationWithName:@"scratch"WithCount:56];

}

- (IBAction)tomCatFart:(id)sender {

[selftomCatAnimationWithName:@"fart"WithCount:28];

}

- (IBAction)tomCatCymbal:(id)sender { [selftomCatAnimationWithName:@"cymbal"WithCount:13];

}

- (IBAction)tomCatDrink:(id)sender {

[selftomCatAnimationWithName:@"drink"WithCount:40];

}

- (IBAction)tomCatPie:(id)sender {

[selftomCatAnimationWithName:@"pie"WithCount:24];

}

- (IBAction)tomCatStomach:(id)sender { [selftomCatAnimationWithName:@"stomach"WithCount:34];

}

- (IBAction)tomCatKnockout:(id)sender {

[selftomCatAnimationWithName:@"knockout"WithCount:81];

}

- (IBAction)tomCatFootRight:(id)sender {

[selftomCatAnimationWithName:@"footLeft"WithCount:30];

}

- (IBAction)tomCatFootLeft:(id)sender {

[selftomCatAnimationWithName:@"footRight"WithCount:30];

}

- (IBAction)tomCatAngery:(id)sender {[selftomCatAnimationWithName:@"angry"WithCount:26];

}

總結(jié):

//序列幀動畫要播放的圖片數(shù)組

//imageView.animationImages

//序列幀動畫時長

//imageView.animationDuration

//重復(fù)次數(shù)

//imageView.animationRepeatCount

//開始動畫

//[imageView startAnimating];

//結(jié)束動畫

//[imageview stopAnimating];

//是否正在執(zhí)行動畫

//[imageView isAnimating];

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容