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
uiimageView连续帧动画的更多相关文章
- [Xcode 实际操作]六、媒体与动画-(13)使用UIImageView制作帧动画
目录:[Swift]Xcode实际操作 本文将演示如何将导入的序列图片,转换为帧动画. 在项目导航区打开资源文件夹[Assets.xcassets] [+]->[Import]->选择图片 ...
- IOS UIImageView的帧动画
● UIImageView可以让一系列的图片在特定的时间内按顺序显示 ● 相关属性解析: ● animationImages:要显示的图片(一个装着UIImage的NSArray) ● animati ...
- UIImageView有关的帧动画
纯代码:设置imageView帧动画 @interface ViewController () { UIImageView *_imgView; NSMutableArray<UIImage * ...
- 【iOS系列】-UIImageView帧动画相关属性介绍
UIImageView帧动画相关属性介绍 1:相关属性: //An array of UIImage objects to use for an animation.存放UIImage对象,会按顺序显 ...
- UIImageView帧动画相关属性和方法
@property(nonatomic,copy) NSArray *animationImages; 需要播放的序列帧图片数组(里面都是UIImage对象,会按顺序显示里面的图片) @propert ...
- 帧动画 连续播放多张图片动画 以及ui动画 SoundPool
drawable下有很多图片 可以 <?xml version="1.0" encoding="utf-8"?> <animation-li ...
- Android 逐帧动画
原理: 逐帧动画是最简单的一种动画.原理就是把几张图片连续显示出来,以达到动画的效果.就相当于下面这种手绘翻页动画啦~ 实现: 1.需要建立一个animation-list来设置静态图片资源.持续时间 ...
- Android动画总结#补间动画(Tween Animation/View Animation) #帧动画(Frame Animation/Drawable Animation)#属性动画(PropertyAnimation)
1.共有三种动画,英文名字多种叫法如下 第一种动画:补间动画(Tween Animation/View Animation) 四个:RotateAnimation旋转. AlphaAnimation透 ...
- animation中的steps()逐帧动画
在我们平时做宽高确定,需要背景图片切换的效果时,我如果用的是一张大的png图片.而且恰好是所有小图都是从左向右排列的,那么 我们只需测量出某一个小图距左侧有多少像素(x),然后我们banckgroun ...
随机推荐
- Ubuntu安装Flash
第一步:打开视频网站,随意点击一个视频,会提示需要先安装Flash,点击它所提供的链接. 第二步:根据系统选择合适的版本进行下载,有红帽的yum版本,我选择的是tar.gz for other Lin ...
- 【翻译】KNACK制作介绍
KNACK 次世代游戏机的性能开发新世界,PlayStation 4首发游戏的舞台幕后 配合PS4的国内首发,作为SCE的第一个游戏发售的本作. 一边加入发挥次世代机机能的表现,设计了谁都可以 ...
- JiaThis WordPress分享插件安装全攻略
WordPress 是一个功能非常强大的博客系统,插件众多,易于扩充功能.安装和使用都非常方便.目前 WordPress 已经成为主流的 Blog 搭建平台.按照下面的方法,只需简单几步,就可轻松地将 ...
- MemcacheQ安装及使用
一.MemcacheQ安装记录1.安装libevent查看是否已经安装了libeventrpm -qa|grep libevent如果没有安装使用yum安装yum install libevent l ...
- Python - 求斐波那契数列前N项之和
n = int(input("Input N: ")) a = 0 b = 1 sum = 0 for i in range(n): sum += a a, b = b, a + ...
- [dpdk] 读官方文档(3)
续前节, 测试小程序 1. 想编译测试程序首先需要设置两个环境变量,为什么呢,因为测试程序的Makefile里用了... rpm装了打包好的devel包,这个rpm也会自带这两个环境变量.就是说写第三 ...
- iOS简单排序--字母排序、NSDictionary排序
// 数组用系统方法compare做字母的简单排序 NSArray *oldArray = @[@"bac",@"bzd",@"azc",@ ...
- JavaScript判断字符串的字符长度(中文占两个字符)
判断方法 //判断字符串中的字符 中文算两个字符 function chkstrlen(str) { ; ; i < str.length; i++) { ) //如果是汉字,则字符串长度加2 ...
- SAX解析XML
package ls.xml; import java.io.StreamCorruptedException; import javax.xml.stream.events.EndElement; ...
- ArcGIS API for JavaScript 4.0(一)
原文:ArcGIS API for JavaScript 4.0(一) 最近ArcGIS推出了ArcGIS API for JavaScript 4.0,支持无插件3D显示,而且比较Unity和Sky ...