iOS-TOM猫-汤姆猫动画播放-UIImageVIew
屏幕快照 2016-01-14 上午8.43.19.png

#import "ViewController.h"

@interface ViewController ()
@property (nonatomic, retain) UIImageView *img;
@end

@implementation ViewController

  • (void)viewDidLoad {

    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    self.view.backgroundColor = [UIColor whiteColor];
    self.img = [[UIImageView alloc] initWithFrame:self.view.frame];
    
    [self.view addSubview:self.img];
    

    // [_img release];

self.img.image = [UIImage imageNamed:@"angry_00.jpg"];

// 看见按钮
// 左
// 小鸟
[self xiaonian];
// 爪子
[self zuoTwo];
// 响声
[self xSheng];
// 右
// 放屁
[self fPi];
// 喝奶
[self heN];
// 砸屏
[self zaiping];
// 隐藏按钮
[self anto];
[self anzhon];
[self anxiao];
[self anfootLeft];
[self anfootRight];
[self m];

}

// 小鸟

  • (void)xiaonian
    {
    UIButton *xiaonian = [UIButton buttonWithType:UIButtonTypeSystem];
    xiaonian.frame = CGRectMake(20, 400, 50, 50);
    [xiaonian setBackgroundImage:[UIImage imageNamed:@"eat.png"] forState:UIControlStateNormal];
    [xiaonian addTarget:self action:@selector(xiaonianAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:xiaonian];
    }
  • (void)xiaonianAction
    {

    NSMutableArray *xiaonianArr = [NSMutableArray array];
    for (NSInteger i = 0; i < 39; i++) {

    NSString *imgName = [NSString stringWithFormat:@"eat_%02ld.jpg", i];
    UIImage *img = [UIImage imageNamed:imgName];
    [xiaonianArr addObject:img];

    }
    self.img.animationImages = xiaonianArr;
    self.img.animationRepeatCount = 1;

    [self.img startAnimating];

    }

// 爪子

  • (void)zuoTwo
    {
    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(20, 460, 50, 50);
    [button setBackgroundImage:[UIImage imageNamed:@"scratch.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(zuoTwoAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    }
  • (void)zuoTwoAction
    {

    NSMutableArray *imgArr = [NSMutableArray array];
    for (NSInteger i = 0; i < 56; i++) {

    NSString *imgName = [NSString stringWithFormat:@"scratch_%02ld.jpg", i];
    UIImage *image = [UIImage imageNamed:imgName];
    [imgArr addObject:image];

    }
    self.img.animationImages = imgArr;
    self.img.animationRepeatCount = 1;

    [self.img startAnimating];
    }

// 响声
-(void)xSheng
{

UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button.frame = CGRectMake(20, 520, 50, 50);
[button setBackgroundImage:[UIImage imageNamed:@"cymbal.png"] forState:UIControlStateNormal];
[button addTarget:self action:@selector(xShengAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];

}

  • (void)xShengAction
    {
NSMutableArray *shengArr  = [NSMutableArray array];
for (NSInteger i = 0; i < 12; i++) {
    NSString *str = [NSString stringWithFormat:@"cymbal_%02ld.jpg", i];
    UIImage *img = [UIImage imageNamed:str];
    [shengArr addObject:img];
}
self.img.animationImages = shengArr;
self.img.animationRepeatCount = 1;
self.img.animationDuration = 2;

[self.img startAnimating];

}

// 右
// 放屁

  • (void)fPi
    {

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(300, 400, 50, 50);
    [button setBackgroundImage:[UIImage imageNamed:@"fart.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(fPiAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

    }

  • (void)fPiAction
    {
NSMutableArray *imgArr = [NSMutableArray array];
for (NSInteger i = 0; i < 27; i++) {
    NSString *str = [NSString stringWithFormat:@"fart_%02ld.jpg", i];
    UIImage *imgimg = [UIImage imageNamed:str];
    [imgArr addObject:imgimg];
}
self.img.animationImages = imgArr;
self.img.animationRepeatCount = 1;
self.img.animationDuration = 2;

[self.img startAnimating];

}
// 喝奶

  • (void)heN
    {

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(300, 460, 50, 50);
    [button setBackgroundImage:[UIImage imageNamed:@"drink.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(heNAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

    }

  • (void)heNAction
    {
NSMutableArray *arr =[NSMutableArray array];
for (NSInteger i = 0; i < 80; i++) {
    NSString *str = [NSString stringWithFormat:@"drink_%02ld.jpg", i];
    UIImage *imgimg = [UIImage imageNamed:str];
    [arr addObject:imgimg];
}
self.img.animationImages = arr;
self.img.animationRepeatCount = 1;
self.img.animationDuration = 5;

[self.img startAnimating];

}
// 砸屏

  • (void)zaiping
    {

    UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
    button.frame = CGRectMake(300, 520, 50, 50);
    [button setBackgroundImage:[UIImage imageNamed:@"pie.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(zaipingAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];

    }

  • (void)zaipingAction
    {
NSMutableArray *arr = [NSMutableArray array];
for (NSInteger i = 0; i < 23; i++) {
    NSString *str = [NSString stringWithFormat:@"pie_%02ld.jpg", i];
    UIImage *imgN = [UIImage imageNamed:str];
    [arr addObject:imgN];
}
self.img.animationImages = arr;
self.img.animationRepeatCount = 1;

[self.img startAnimating];

}

// 隐藏按钮

  • (void)anto
    {
    UIButton *anto = [UIButton buttonWithType:UIButtonTypeSystem];
    anto.frame = CGRectMake(130, 200, 120, 120);
    // anto.backgroundColor = [UIColor yellowColor];
    [anto addTarget:self action:@selector(anTom) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:anto];

    }

  • (void)anTom
    {
    NSMutableArray *imgTom = [NSMutableArray array];
    for (NSInteger i = 0; i < 80; i ++) {

    [imgTom addObject:[UIImage imageNamed:[NSString stringWithFormat:@"knockout_%02ld.jpg", i]]];
    

    }
    self.img.animationDuration = 5;
    self.img.animationImages = imgTom;
    self.img.animationRepeatCount = 1;
    [self.img startAnimating];

    }

  • (void)anzhon
    {
    UIButton *anzhon = [UIButton buttonWithType:UIButtonTypeSystem];
    anzhon.frame = CGRectMake(140, 400, 100, 100);
    // anzhon.backgroundColor = [UIColor yellowColor];
    [anzhon addTarget:self action:@selector(anZhon) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:anzhon];

    }

  • (void)anZhon
    {
    NSMutableArray *imgTom = [NSMutableArray array];
    for (NSInteger i = 0; i < 33; i++) {

    [imgTom addObject:[UIImage imageNamed:[NSString stringWithFormat:@"stomach_%02ld.jpg",i]]];

    }
    self.img.animationDuration = 3;
    self.img.animationImages = imgTom;
    self.img.animationRepeatCount = 1;
    [self.img startAnimating];
    }

  • (void)anxiao
    {
    UIButton *anxiao = [UIButton buttonWithType:UIButtonTypeSystem];
    anxiao.frame = CGRectMake(160, 550, 50, 50);
    // anxiao.backgroundColor = [UIColor yellowColor];
    [anxiao addTarget:self action:@selector(anXiao) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:anxiao];
    }
  • (void)anXiao
    {
    NSMutableArray *imgTom = [NSMutableArray array];
    for (NSInteger i = 1; i < 18; i++) {

    [imgTom addObject:[UIImage imageNamed:[NSString stringWithFormat:@"stomach_%02ld.jpg", i]]];

    // [imgTom addObject:[UIImage imageNamed:[NSString stringWithFormat:@"a0%ld.png", i]]];
    }
    self.img.animationDuration = 5;
    self.img.animationImages = imgTom;
    self.img.animationRepeatCount = 1;
    [self.img startAnimating];
    }

  • (void)anfootLeft

{

UIButton *anfootLeft = [UIButton buttonWithType:UIButtonTypeSystem];
anfootLeft.frame = CGRectMake(140, 610, 35, 35);
// anfootLeft.backgroundColor = [UIColor yellowColor];
[anfootLeft addTarget:self action:@selector(anright) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:anfootLeft];

}

  • (void)anright
    {
    NSMutableArray *imgTom = [NSMutableArray array];
    for (NSInteger i = 0; i < 29; i++) {

    [imgTom addObject:[UIImage imageNamed:[NSString stringWithFormat:@"footRight_%02ld.jpg", i]]];
    

    }
    self.img.animationDuration = 3;
    self.img.animationImages = imgTom;
    self.img.animationRepeatCount = 1;
    [self.img startAnimating];
    }

  • (void)anfootRight
    {
    UIButton *anfootright = [UIButton buttonWithType:UIButtonTypeSystem];
    anfootright.frame = CGRectMake(200, 610, 35, 35);
    // anfootright.backgroundColor = [UIColor yellowColor];
    [anfootright addTarget:self action:@selector(anlift) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:anfootright];
    }
  • (void)anlift
    {
    NSMutableArray *imgTom = [NSMutableArray array];
    for (NSInteger i = 0; i < 29; i++) {

    [imgTom addObject:[UIImage imageNamed:[NSString stringWithFormat:@"footLeft_%02ld.jpg",i]]];

    }
    self.img.animationDuration = 2;
    self.img.animationImages = imgTom;
    self.img.animationRepeatCount = 1;
    [self.img startAnimating];
    }

// 隐藏动画

  • (void)m
    {
    UIButton *an = [UIButton buttonWithType:UIButtonTypeSystem];
    an.frame = CGRectMake(0, 0, 50, 50);
    [an addTarget:self action:@selector(anAction) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:an];
    }
  • (void)anAction
    {
    NSMutableArray *imgTom = [NSMutableArray array];
    for (NSInteger i = 1; i < 18; i++) {

    [imgTom addObject:[UIImage imageNamed:[NSString stringWithFormat:@"a0%ld.png", i ]]];
    

    }
    self.img.animationDuration = 18;
    self.img.animationImages = imgTom;
    self.img.animationRepeatCount = 1;
    [self.img startAnimating];
    }

屏幕快照 2016-01-14 上午8.40.21.png
屏幕快照 2016-01-14 上午8.40.55.png
屏幕快照 2016-01-14 上午8.41.03.png
屏幕快照 2016-01-14 上午8.41.16.png
屏幕快照 2016-01-14 上午8.41.25.png
屏幕快照 2016-01-14 上午8.41.37.png
屏幕快照 2016-01-14 上午8.41.52.png
屏幕快照 2016-01-14 上午8.42.02.png
屏幕快照 2016-01-14 上午8.42.14.png
屏幕快照 2016-01-14 上午8.42.24.png
屏幕快照 2016-01-14 上午8.42.33.png
屏幕快照 2016-01-14 上午8.42.40.png
屏幕快照 2016-01-14 上午8.42.50.png
屏幕快照 2016-01-14 上午8.42.59.png
屏幕快照 2016-01-14 上午8.43.06.png