//

//  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. HDU 2181 哈密顿绕行世界问题(经典DFS+回溯)

    哈密顿绕行世界问题 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total ...

  2. HDU 2089 数位dp入门

    开始学习数位dp...一道昨天看过代码思想的题今天打了近两个小时..最后还是看了别人的代码找bug...(丢丢) 传说院赛要取消 ? ... 这么菜不出去丢人也好吧~ #include<stdi ...

  3. 下载、运行docker

    Get the Linux binary To download the latest version for Linux, use the following URLs: https://get.d ...

  4. Ubuntu安装和设置SSH服务

    1.安装 Ubuntu缺省安装了openssh-client,所以在这里就不安装了,如果你的系统没有安装的话,再用apt-get安装上即可. 安装ssh-server sudo apt-get ins ...

  5. wdate-year-month-week-gategory-amount-coin

    ---2016-12-02 19:46:39 the whole table DISTINCT field SUM(field) COUNT(field) --- 888983 rows OK SEL ...

  6. storm-kafka-0.8-plus 源码解析

    https://github.com/wurstmeister/storm-kafka-0.8-plus http://blog.csdn.net/xeseo/article/details/1861 ...

  7. VS C++ 从一个窗口创建另一个窗口

    一.在stdafx.h文件中,添加: #include "Form2.h" / stdafx.h : 标准系统包含文件的包含文件, // 或是经常使用但不常更改的 // 特定于项目 ...

  8. Lazarus中TScreen类使用介绍

    描述:虚拟屏幕(桌面)可以包含多个物理显示器.Screen对象是鼠标指针.字体.窗体. 对于Delphi兼容的(不可见)DataModules也被列出了. 同时也追踪当前活动窗体窗体.控件和指针. S ...

  9. svn 入门

    SVN版本:1.5 及更新版本 名词说明: WC:Working Copy 你的工作区 Versioned:受控的:受版本控制的 SVN是什么? SVN是开源的版本控制系统. 比CVS更多的特性.一个 ...

  10. charles 使用 技巧

    测试的是Android ,App , 在 手机wifi 网络代理设置为 电脑代理. 然后,手机访问的网络 都通过 电脑端的 charles监控!