首页 > 其他 > 详细

Tom汤姆猫的简单实现

时间:2015-02-17 17:35:58      阅读:126      评论: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
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!