UI010---cat tom

前面要再storyboard设置
这里写图片描述

并连好线
设置了两个透明的button
和喝牛奶的button

 //

//  CBViewController.m

//  05-汤姆猫

//

//  Created by apple on 15-7-24.

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

//


#import "CBViewController.h"


@interface CBViewController ()

- (IBAction)drink;

- (IBAction)knock;

- (IBAction)rightFoot;


/** 这是一只显示图片的猫 */

@property (weak, nonatomic) IBOutletUIImageView *tom;


@end


@implementation MJViewController

/** 播放动画 */

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

{

    if (self.tom.isAnimating)return;



    // 1.加载所有的动画图片

    NSMutableArray *images = [NSMutableArrayarray];



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

        // 计算文件名

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

        // 加载图片



        // imageNamed: 有缓存(传入文件名)

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



        // imageWithContentsOfFile: 没有缓存(传入文件的全路径)

        NSBundle *bundle = [NSBundle mainBundle];

        NSString *path = [bundle pathForResource:filenameofType:nil];

        UIImage *image = [UIImage imageWithContentsOfFile:path];



        // 添加图片到数组中

        [images addObject:image];

    }

    self.tom.animationImages = images;



    // 2.设置播放次数(1次)

    self.tom.animationRepeatCount =1;



    // 3.设置播放时间

    self.tom.animationDuration = images.count * 0.05;



    [self.tomstartAnimating];



    // 4.动画放完1秒后清除内存

    CGFloat delay =self.tom.animationDuration +1.0;

    [self.tomperformSelector:@selector(setAnimationImages:)withObject:nilafterDelay:delay];

//    [self performSelector:@selector(clearCache) withObject:nil afterDelay:delay];

}


//- (void)clearCache

//{

    self.tom.animationImages = nil;

//    

//    [self.tom setAnimationImages:nil];

//}


- (IBAction)drink {

    [selfrunAnimationWithCount:81name:@"drink"];



//    if (self.tom.isAnimating) return;

//    

//    // 1.加载所有的动画图片

//    NSMutableArray *images = [NSMutableArray array];

//    

//    for (int i = 0; i<81; i++) {

//        // 计算文件名

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

//        // 加载图片

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

//        // 添加图片到数组中

//        [images addObject:image];

//    }

//    self.tom.animationImages = images;

//    

//    // 2.设置播放次数(1次)

//    self.tom.animationRepeatCount = 1;

//    

//    // 3.设置播放时间

//    self.tom.animationDuration = images.count * 0.05;

//    

//    [self.tom startAnimating];

}


- (IBAction)knock {

    [selfrunAnimationWithCount:81name:@"knockout"];

}


- (IBAction)rightFoot {

    [selfrunAnimationWithCount:30name:@"footRight"];

}

@end
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值