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 {
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 40;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"eat_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed: imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 40*0.075;
// 设置动画重复次数
self.tomcatView.animationRepeatCount = 1;
// 开始动画
[self.tomcatView startAnimating];
}
- (IBAction)tomCatScratch:(UIButton *)sender {
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 55;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"scratch_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed: imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 55*0.075;
// 设置动画重复次数
self.tomcatView.animationRepeatCount = 1;
// 开始动画
[self.tomcatView startAnimating];
}
- (IBAction)tomCatFootLeft:(UIButton *)sender {
//// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 30;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"footLeft_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed: imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 30*0.075;
// 设置动画重复次数
self.tomcatView.animationRepeatCount = 1;
// 开始动画
[self.tomcatView startAnimating];
}
- (IBAction)tomCatFootRight:(UIButton *)sender {
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 30;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"footRight_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed: imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 30*0.075;
// 设置动画重复次数
self.tomcatView.animationRepeatCount = 1;
// 开始动画
[self.tomcatView startAnimating];
}
- (IBAction)tomCatFart:(UIButton *)sender {
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 27;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"fart_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed: imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 27*0.075;
// 设置动画重复次数
self.tomcatView.animationRepeatCount = 1;
// 开始动画
[self.tomcatView startAnimating];
}
- (IBAction)tomCatCymbal:(UIButton *)sender {
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 12;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"cymbal_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed: imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 12*0.075;
// 设置动画重复次数
self.tomcatView.animationRepeatCount = 1;
// 开始动画
[self.tomcatView startAnimating];
}
- (IBAction)tomCatDrink:(UIButton *)sender {
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 80;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"drink_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 80*0.075;
// 设置动画重复次数
self.tomcatView.animationRepeatCount = 1;
// 开始动画
[self.tomcatView startAnimating];
}
- (IBAction)tomCatPlain:(UIButton *)sender {
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 23;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"pie_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed: imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 23*0.075;
// 设置动画重复次数
self.tomcatView.animationRepeatCount = 1;
// 开始动画
[self.tomcatView startAnimating];
}
- (IBAction)tomCatStomach:(UIButton *)sender {
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 33;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"stomach_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed: imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 33*0.075;
// 设置动画重复次数
self.tomcatView.animationRepeatCount = 1;
// 开始动画
[self.tomcatView startAnimating];
}
- (IBAction)tomCatKnockout:(UIButton *)sender {
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0;i < 80;i ++) {
// 根据i 来加载图片,然后添加到可变数组images 里面
// 格式化创建字符串
NSString *imageName = [NSString stringWithFormat:@"knockout_%02ld.jpg",i];
// 根据格式化的图片名加载图片image
UIImage *image = [UIImage imageNamed: imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomcatView.animationImages = images;
// 设置动画时长
self.tomcatView.animationDuration = 80*0.075;
// 设置动画重复次数
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];
//序列帧动画要播放的图片数组
//imageView.animationImages
//序列帧动画时长
//imageView.animationDuration
//重复次数
//imageView.animationRepeatCount
//开始动画
//[imageView startAnimating];
//结束动画
//[imageview stopAnimating];
//是否正在执行动画
//[imageView isAnimating];
-(void)tomCatAnimationWithName:(NSString*)name WithCount:(NSInteger)count{
if([self.tomcatViewisAnimating]) {
return;
}
//创建可变数组images,负责存放要播放的图片数组
NSMutableArray*images = [NSMutableArrayarray];
for(NSIntegeri =0;i < count;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:(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];
}
总结:
//序列帧动画要播放的图片数组
//imageView.animationImages
//序列帧动画时长
//imageView.animationDuration
//重复次数
//imageView.animationRepeatCount
//开始动画
//[imageView startAnimating];
//结束动画
//[imageview stopAnimating];
//是否正在执行动画
//[imageView isAnimating];