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 ...
随机推荐
- Android基础知识
一.四大组件 Activity(活动).Service(服务).BroadcastReceiver(广播器).Content Provider(内容提供器) 二.五大布局 LinearLayout(线 ...
- tableView在加载数据成功之前先展示了footerView-医生工作台1期
一进入这个页面先显示了footreView 解: 发现先走的requestData,但是请求接口成功的回调没走,走了configUI configUI之后,走了requestData 所以 ...
- a compromise between lock overhead and data safety
High Performance My SQL THIRD EDITION A locking strategy is a compromise between lock overhead and ...
- Locking
Computer Science An Overview _J. Glenn Brookshear _11th Edition To solve such problems, a DBMS could ...
- 批处理快速创建wifi
为什么要用cmd这种古老的东西创建wifi呢,电脑管家.360安全卫士都有这种插件,一键开启关闭,多方便啊! 开始用的也是电脑管家的免费wifi插件,但是我越来越不能忍它极慢的启动关闭过程,每一次看着 ...
- php session 跨页失效问题
原因是session.savepath 目录不存在或者没有读写权限
- Jetbrains phpstorm pycharm 免费授权注册码
通过授权服务器授权 jetbrains是一家专门做IDE的软件公司,软件也非常好用,但是授权特别贵,下面就说说免费的方式,就是使用授权服务器,地址:http://idea.qinxi1992.cn 自 ...
- [Virtualization][SDN] 讲的很好的SDN软件定义网络视频课程
51CTO的免费课程,开始以为是扯蛋的,后来看了一下,讲的很好.注册一下,免费的. 只看了导论,挺好的. http://edu.51cto.com/course/course_id-4466.html
- 设计模式:观察者模式(Observer)
定 义:定义了一种一对多的依赖关系,让多个观察者对象同时监听某一主题对象.这个主题对象在状态发生 变化时,会通知所有观察者对象,使他们能够自动更新自己. 结构图: 抽象主题类: abstract c ...
- Magento订单打印(pdf格式)
Magento自身包含有:打印发票单,打印装箱单,打印退款单.这些都是基于西方国家的习惯来布置的.公司有个需求就是打印订单的四联单,PDF格式的,要一周内完成.刚接到这个任务时,觉得头大,因为对于PH ...