//
// YJViewController.m
// 04-汤姆猫的理解
//
// Created by JACKY-MAC on 15-5-31.
// Copyright (c) 2015年 www.train.com. All rights reserved.
//
#import "YJViewController.h"
@interface YJViewController ()
@property (weak, nonatomic) IBOutlet UIImageView *tom;
@end
@implementation YJViewController
- (void)tomAnimationWithName:(NSString *) name andCount:(NSInteger)count
{
if ([self.tom isAnimating]) return;
// 动画图片的数
NSMutableArray *arrayM = [NSMutableArray array];
// 添加动画播放的图片
for (int i=0; i<count; i++) {
// 图像名称
NSString *imageName = [NSString stringWithFormat:@"%@_%02d.jpg",name,i];
NSString *path = [[NSBundle mainBundle] pathForResource:imageName ofType:nil];
UIImage *image = [UIImage imageWithContentsOfFile:path];
[arrayM addObject:image];
}
// 设置动画数组
self.tom.animationImages = arrayM;
// 重复1次
self.tom.animationRepeatCount = 1;
// 动画时长
self.tom.animationDuration = self.tom.animationImages.count * 0.075;
// 开始动画
[self.tom startAnimating];
// 动画"结束"之后,清理动画数组
[self.tom performSelector:@selector(setAnimationImages:) withObject:nil
afterDelay:self.tom.animationDuration];
}
/*
- (IBAction)tomAction:(UIButton *)sender
{
// currentTitle 可以取出按钮当前的标题文字
[self tomAnimationWithName:sender.currentTitle andCount:sender.tag];
}
*/
- (IBAction)knockout
{
[self tomAnimationWithName:@"knockout" andCount:81];
}
- (IBAction)eat
{
[self tomAnimationWithName:@"eat" andCount:40];
}
- (IBAction)cymbal
{
[self tomAnimationWithName:@"cymbal" andCount:12];
}
- (IBAction)drink
{
[self tomAnimationWithName:@"drink" andCount:80];
}
- (IBAction)fart
{
[self tomAnimationWithName:@"fart" andCount:27];
}
-(IBAction)pie
{
[self tomAnimationWithName:@"pie" andCount:23];
}
- (IBAction)scratch
{
[self tomAnimationWithName:@"scratch" andCount:55];
}
- (IBAction)stomach
{
[self tomAnimationWithName:@"stomach" andCount:34];
}
- (IBAction)footLeft
{
[self tomAnimationWithName:@"footLeft" andCount:30];
}
- (IBAction)footRight
{
[self tomAnimationWithName:@"footRight" andCount:30];
}
@end