//
// ViewController.m
// TOM CAT
//
// Created by ADONIS 16/7/12.
// Copyright © 2016年 LESSON 2. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tomCatView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
UIImageView *imageView = [UIImageView new];
/*
// 序列帧动画要播放的图片数组
imageView.animationImages ;
// 序列帧动画的播放时长
imageView.animationDuration ;
// 序列帧动画的重复次数
imageView.animationRepeatCount ;
// 开始动画
[imageView startAnimating];
// 结束动画
[imageView stopAnimating];
// 是否正在执行动画
[imageView isAnimating];
*/
}
// 以下将重复代码构建成方法方便调用
-(void)setTomCatAnimationWithName:
(NSString*)name withCount:(NSInteger)count
{
// 判断该动画是否正在执行
if ([self.tomCatView isAnimating])
{
return;
}
// 创建可变数组images,负责存放要播放的图片数组
NSMutableArray *images=[NSMutableArray array];
for (NSInteger i=0; i<count; i++)
{
// 根据i来加载图片,然后添加到可变数组images里面
NSString *imageName=[NSString stringWithFormat:@"%@_%02ld.jpg",name,i];
// 根据格式化的图片名加载图片image
UIImage *image=[UIImage imageNamed:imageName];
// 将图片image添加到数组images中
[images addObject:image];
}
// 设置动画图片数组
self.tomCatView.animationImages=images;
// 设置动画时长
self.tomCatView.animationDuration=count*0.075;
// 设置动画重复次数
self.tomCatView.animationRepeatCount=1;
// 开始动画
[self.tomCatView startAnimating];
}
- (IBAction)eatBirdAction:(UIButton *)sender
{ [self setTomCatAnimationWithName:@"eat"withCount:40]; /*
// 添加可变数组存放图片
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)cymabl:(UIButton *)sender
{ // 调用刚刚的重复代码串
[self setTomCatAnimationWithName:@"cymbal"withCount:13];
/*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i < 13; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"cymbal_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration = 13*0.1;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (IBAction)drink:(UIButton *)sender
{
[self setTomCatAnimationWithName:@"drink"withCount:81]; /*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i < 81; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"drink_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration = 81*0.075;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (IBAction)fart:(UIButton *)sender
{
[self setTomCatAnimationWithName:@"fart"withCount:28];
/*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i <28; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"fart_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration = 28*0.1;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (IBAction)pie:(UIButton *)sender
{
[self setTomCatAnimationWithName:@"pie"withCount:24];
/*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i < 24; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"pie_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration = 24*0.1;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (IBAction)scratch:(UIButton *)sender
{
[self setTomCatAnimationWithName:@"scratch"withCount:56];
/*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i < 56; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"scratch_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration = 56*0.075;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (IBAction)footLeft:(UIButton *)sender
{[self setTomCatAnimationWithName:@"footRight"withCount:30];
/*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i < 30; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"footRight_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration = 30*0.075;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (IBAction)rootRight:(UIButton *)sender
{
[self setTomCatAnimationWithName:@"footLeft"withCount:30];
/*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i < 30; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"footLeft_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration = 30*0.075;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (IBAction)stomach:(UIButton *)sender
{
[self setTomCatAnimationWithName:@"stomach"withCount:34];
/*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i < 34; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"stomach_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration =34*0.075;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (IBAction)knock:(UIButton *)sender
{
[self setTomCatAnimationWithName:@"knockout"withCount:81];
/*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i < 81; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"knockout_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration = 81*0.075;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (IBAction)angry:(UIButton *)sender
{
[self setTomCatAnimationWithName:@"angry"withCount:26];
/*
// 添加可变数组存放图片
NSMutableArray *images = [NSMutableArray array];
for (NSInteger i = 0; i < 26; i++)
{
// 根据i来加载图片 然后添加到可变数组images里面
NSString *imageName = [NSString stringWithFormat:@"angry_%02ld.jpg",i ];
UIImage *image = [UIImage imageNamed:imageName];
[images addObject:image];
}
// 序列帧动画要播放的图片数组
self.tomCatView.animationImages = images;
// 序列帧动画的播放时长
self.tomCatView.animationDuration = 26*0.075;
// 序列帧动画的重复次数
self.tomCatView.animationRepeatCount = 1;
// 上传到调试窗口
[self.tomCatView startAnimating];
*/
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
TOM猫部分代码
最新推荐文章于 2022-02-23 21:50:07 发布