zoukankan      html  css  js  c++  java
  • uiimageView连续帧动画

    //

    //  MJViewController.m

    //  05-汤姆猫

    //

    //  Created by apple on 14-3-24.

    //  Copyright (c) 2014年 itcast. All rights reserved.

    //

    #import "MJViewController.h"

    @interface MJViewController ()

    - (IBAction)drink;

    - (IBAction)knock;

    - (IBAction)rightFoot;

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

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

    @end

    @implementation MJViewController

    /** 播放动画 */

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

    {

        if (self.tom.isAnimating) return;

        

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

        NSMutableArray *images = [NSMutableArray array];

        

        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:filename ofType: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.tom startAnimating];

        

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

        CGFloat delay = self.tom.animationDuration + 1.0;

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

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

    }

    //- (void)clearCache

    //{

    ////    self.tom.animationImages = nil;

    //    

    //    [self.tom setAnimationImages:nil];

    //}

    - (IBAction)drink {

        [self runAnimationWithCount:81 name:@"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 {

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

    }

    - (IBAction)rightFoot {

        [self runAnimationWithCount:30 name:@"footRight"];

    }

    @end

  • 相关阅读:
    代码书写的细节
    php中的正则函数主要有三个-正则匹配,正则替换
    2个比较经典的PHP加密解密函数分享
    淘宝运营中的6大致命误区,你犯过么?
    30分钟教你写出10分的淘宝标题
    超全的web开发工具和资源
    转化率不好?告诉你转化飙秘诀
    帮你店铺日销千单的20个淘宝小技巧
    不刷单,中小卖家如何提升店铺流量?
    使用Flexible实现手淘H5页面的终端适配
  • 原文地址:https://www.cnblogs.com/supper-Ho/p/6206335.html
Copyright © 2011-2022 走看看