//

//  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

uiimageView连续帧动画的更多相关文章

  1. [Xcode 实际操作]六、媒体与动画-(13)使用UIImageView制作帧动画

    目录:[Swift]Xcode实际操作 本文将演示如何将导入的序列图片,转换为帧动画. 在项目导航区打开资源文件夹[Assets.xcassets] [+]->[Import]->选择图片 ...

  2. IOS UIImageView的帧动画

    ● UIImageView可以让一系列的图片在特定的时间内按顺序显示 ● 相关属性解析: ● animationImages:要显示的图片(一个装着UIImage的NSArray) ● animati ...

  3. UIImageView有关的帧动画

    纯代码:设置imageView帧动画 @interface ViewController () { UIImageView *_imgView; NSMutableArray<UIImage * ...

  4. 【iOS系列】-UIImageView帧动画相关属性介绍

    UIImageView帧动画相关属性介绍 1:相关属性: //An array of UIImage objects to use for an animation.存放UIImage对象,会按顺序显 ...

  5. UIImageView帧动画相关属性和方法

    @property(nonatomic,copy) NSArray *animationImages; 需要播放的序列帧图片数组(里面都是UIImage对象,会按顺序显示里面的图片) @propert ...

  6. 帧动画 连续播放多张图片动画 以及ui动画 SoundPool

    drawable下有很多图片  可以 <?xml version="1.0" encoding="utf-8"?> <animation-li ...

  7. Android 逐帧动画

    原理: 逐帧动画是最简单的一种动画.原理就是把几张图片连续显示出来,以达到动画的效果.就相当于下面这种手绘翻页动画啦~ 实现: 1.需要建立一个animation-list来设置静态图片资源.持续时间 ...

  8. Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)

    1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...

  9. animation中的steps()逐帧动画

    在我们平时做宽高确定,需要背景图片切换的效果时,我如果用的是一张大的png图片.而且恰好是所有小图都是从左向右排列的,那么 我们只需测量出某一个小图距左侧有多少像素(x),然后我们banckgroun ...

随机推荐

  1. 自己翻译 delegation 官方文档

    什么是代理,知道怎么用,见过N次.会用代理传值,还不够.代理到底是用来干嘛的嘛?还是看看官方文档吧,自己翻译出来看看是不是通顺 代理: 代理是一个简单高效的模式,尤其是一个类在编程的过程中代表或者需要 ...

  2. maven仓库私服配置

    私服访问地址:[[http://192.168.1.252:9080/nexus/content/groups/public/ 地址]] 1. 打开eclipse/myeclipse的maven插件: ...

  3. PHP 错误与异常 笔记与总结(10)错误处理器测试

    关联文件:myErrorHandler.php (上一篇) 先测试通知级别的错误的自定义处理: testErrorHandler.php <?php require_once 'myErrorH ...

  4. Socket简介

    本文全部摘抄http://c.biancheng.net/cpp/html/3029.html 大多数项目是在Linux下开发服务器端,而在Windows下开发客户端,需要经常在两大平台之间进行切换, ...

  5. Jquery--string

    --判断string是否为空 state !== undefined || state !== null || state != ""

  6. faker image

    $faker->image http://placehold.it http://placekitten.com/g/200/300 带文字 https://placeholdit.imgix. ...

  7. windows系统中ubuntu虚拟机安装及web项目到服务上(一)

    一:ununtu虚拟机安装 安装vm, 桥接,换国内源,安装ssh 服务 装jdk,装tomcat,装mysql, 部署,完成 主要用到的软件工具 Xmanager Enterprise 4,VMwa ...

  8. [转自Kevins的天空 http://rootsec.cn]rad studio 2007 up3方法

    rad studio 2007 网络下载点: http://bbs.hnhyxy.com/bcb/CodeGear.RAD.Studio.2007.rar http://andy.jgknet.de/ ...

  9. Git相关的项目

    1.posh-git Git的PowerShell扩展 项目地址: https://github.com/dahlbyk/posh-git 可以用psget快速安装扩展模块,psget下载安装地址 h ...

  10. 【转】Cocos2d - 观察者模式NotificationCenter

    http://shahdza.blog.51cto.com/2410787/1611575 [唠叨] 观察者模式 也叫订阅/发布(Subscribe/Publish)模式,是 MVC( 模型-视图-控 ...