码迷,mamicode.com
首页 > 其他好文 > 详细

Tom汤姆猫的简单实现

时间:2015-02-17 17:38:42      阅读:573      评论:0      收藏:0      [点我收藏+]

标签:

//

//  ViewController.m

//  TomCat

//

//  Created by 黄松凯 on 15/2/17.

//  Copyright (c) 2015年 SK. All rights reserved.

//

 

#import "ViewController.h"

 

@interface ViewController ()

- (IBAction)drink;

- (IBAction)head;

- (IBAction)cymbal;

- (IBAction)fart;

- (IBAction)scratch;

- (IBAction)eat;

 

- (IBAction)pie;

@property (weak, nonatomic) IBOutlet UIImageView *tom;

 

@end

 

@implementation ViewController

 

- (void)viewDidLoad {

    [super viewDidLoad];

}

//将方法进行封装,可以

-(void)runAnimationWithCount:(int)count name:(NSString *)name

{

    

    if(self.tom.isAnimating)//如果正在喝牛奶,则不要打断

        return;

    

    //加载所有的动画图片

    NSMutableArray *images=[NSMutableArray array];

    

    

    for(int i=0;i<count;i++)

    {

        //文件名

        NSString *filename=[NSString stringWithFormat:@"%@_%02d.jpg",name,i];

        //加载图片(这种方法有缓存,不利用内存优化)

       // UIImage *image=[UIImage imageNamed:filename];

        //添加图片到数组中

        //[images addObject:image];

        

        NSBundle *bundle=[NSBundle mainBundle];

        NSString *path=[bundle pathForResource:filename ofType:nil];

        UIImage *image=[UIImage imageWithContentsOfFile:path];

        [images addObject:image];

     

        

    }

    

    self.tom.animationImages=images;

    

    //设置播放次数

    self.tom.animationRepeatCount=1;

    //设置播放时间

    self.tom.animationDuration=2.0;

    

    //开始播放

    [self.tom startAnimating];

    CGFloat delay=self.tom.animationDuration+1;

    

    [self.tom performSelector:@selector(setAnimationImages:) withObject:nil afterDelay:delay];

   

    

}

 

 

- (IBAction)drink

{

    [self runAnimationWithCount:81 name:@"drink"];

    

}

 

- (IBAction)head {

    

    [self runAnimationWithCount:81 name:@"knockout"];

    

}

 

- (IBAction)cymbal {

    [self runAnimationWithCount:13 name:@"cymbal"];

 

    

}

 

- (IBAction)fart {

    

    [self runAnimationWithCount:28 name:@"fart"];

 

}

 

- (IBAction)scratch {

    [self runAnimationWithCount:56 name:@"scratch"];

 

}

 

- (IBAction)eat {

    [self runAnimationWithCount:40 name:@"eat"];

 

}

 

- (IBAction)pie {

    [self runAnimationWithCount:24 name:@"pie"];

 

}

@end

 

Tom汤姆猫的简单实现

标签:

原文地址:http://www.cnblogs.com/SKuncle/p/4295347.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!