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 ...
随机推荐
- could not build module 'uikit'
今天 新建一个SingleView-APP 无法运行程序,在 AppDelegate.h中 第一行代码处报错. #import <UIKit/UIKit.h> /Users/wjw/Des ...
- CSS2系列:BFC(块级格式化上下文)IFC(行级格式化上下文)
BFC 块级格式化上下文,不好理解,我们暂且把她理解成"具有特殊的一类元素" 哪些元素会生成BFC? 根元素 float属性不为none position为absolute或fix ...
- 40. 特殊a串数列求和
特殊a串数列求和 #include <stdio.h> int main() { int i, a, n, item, sum, temp; while (scanf("%d % ...
- PHP 文件系统管理函数与 preg_replace() 函数过滤代码
案例:在带行号的代码至文件 crop.js 中.用两种方法去掉代码前面的行号,带行号的代码片段: 1.$(function(){ 2. //初始化图片区域 3. var myimg = new Ima ...
- 读取C#AssemblyInfo文件中的AssemblyVersion中的值
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString(); 1.程序集的版本信息由下面四个值组成:主 ...
- js 定时跳转, 格式化字符串时间
效果 1.js中将一字符串表示的系统时间转换为Date时间对象 //js中将一串字符串转换为date类型,主要是先过滤字符,然后分割开 function parseToDate(strTime) { ...
- 【Android测试】【第三节】ADB——源码浅谈
◆版权声明:本文出自carter_dream的博客,转载必须注明出处. 转载请注明出处:http://www.cnblogs.com/by-dream/p/4651724.html 前言 由于本人精力 ...
- PIVOT&UNPIVOT
如果是家电销售员,那么可能需要统计每月日销售的彩电.冰箱.空调...最大值.最小值.平均值等 如果你是耳鼻喉科医生,那么可能需要统计月度年度日接客咽炎.喉炎.鼻炎...最大值.最小值.平均值等 如果你 ...
- C#5.0 .net 4.5示例
//filename: MathOperations.cs using System; using System.Collections.Generic; using System.Linq; usi ...
- CSS3新添加的属性
1.圆角设置 border-radius:15px 50px 30px 5px; /*四个值: 第一个值为左上角,第二个值为右上角,第三个值为右下角,第四个值为左下 角. 三个值: 第一个值为左上角, ...