UIImageView有关的帧动画
纯代码:设置imageView帧动画
@interface ViewController ()
{
UIImageView *_imgView;
NSMutableArray<UIImage *> *_imageArr;
}
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
_imgView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 300, 300, 200)];
_imgView.image = [UIImage imageNamed:@"1.jpg"];
[self.view addSubview:_imgView];
// 1.1 实例化可变数组用来 加载所有的图片
_imageArr = [NSMutableArray array];
for (int i = 0; i<20; i++) {
// 获取图片的名称
NSString *imageName = [NSString stringWithFormat:@"%d", i+1];
// 创建UIImage对象
UIImage *image = [UIImage imageNamed:imageName];
// 加入数组
[_imageArr addObject:image];
}
// 开始按钮
UIButton *imgViewButtonStart = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[imgViewButtonStart setFrame:CGRectMake(20, 200, 200, 50)];
[imgViewButtonStart setTitle:@"开始动画" forState:UIControlStateNormal];
[imgViewButtonStart setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[imgViewButtonStart addTarget:self action:@selector(stratAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:imgViewButtonStart];
// 暂停按钮
UIButton *imgViewButtonStop = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[imgViewButtonStop setFrame:CGRectMake(200, 200, 200, 50)];
[imgViewButtonStop setTitle:@"停止动画" forState:UIControlStateNormal];
[imgViewButtonStop setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[imgViewButtonStop addTarget:self action:@selector(stopAction) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:imgViewButtonStop];
}
#pragma mark - 开始动画
- (void)stratAction {
// 设置动画图片
_imgView.animationImages = _imageArr;
// 设置动画的播放次数
_imgView.animationRepeatCount = 0;
// 设置播放时长
// 1秒30帧, 一张图片的时间 = 1/30 = 0.03333 20 * 0.0333
_imgView.animationDuration = 1.0;
// 开始动画
[_imgView startAnimating];
}
#pragma mark - 结束动画
- (void)stopAction {
[_imgView stopAnimating];
}
@end
UIImageView有关的帧动画的更多相关文章
- [Xcode 实际操作]六、媒体与动画-(13)使用UIImageView制作帧动画
目录:[Swift]Xcode实际操作 本文将演示如何将导入的序列图片,转换为帧动画. 在项目导航区打开资源文件夹[Assets.xcassets] [+]->[Import]->选择图片 ...
- 【iOS系列】-UIImageView帧动画相关属性介绍
UIImageView帧动画相关属性介绍 1:相关属性: //An array of UIImage objects to use for an animation.存放UIImage对象,会按顺序显 ...
- UIImageView帧动画相关属性和方法
@property(nonatomic,copy) NSArray *animationImages; 需要播放的序列帧图片数组(里面都是UIImage对象,会按顺序显示里面的图片) @propert ...
- iOS开发之 -- 帧动画的使用
在项目的开发过程中,我们经常会遇到使用动画的时候,比如我们在请求接口直接开始一个动画,请求结束后结束动画,下面我就给大家展示一个很方便的帧动画的用法: 代码如下: .h #import <Fou ...
- ios9--UIImageView的帧动画
// // ViewController.m // 05-UIImageView的帧动画 // #import "ViewController.h" @interface View ...
- 深入理解CSS3 Animation 帧动画
CSS3我在5年之前就有用了,包括公司项目都一直在很前沿的技术. 最近在写慕课网的七夕主题,用了大量的CSS3动画,但是真的沉淀下来仔细的去深入CSS3动画的各个属性发现还是很深的,这里就写下关于帧动 ...
- Android动画效果之Frame Animation(逐帧动画)
前言: 上一篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画),今天来总结下Android的另外一种动画Frame ...
- android 帧动画,补间动画,属性动画的简单总结
帧动画——FrameAnimation 将一系列图片有序播放,形成动画的效果.其本质是一个Drawable,是一系列图片的集合,本身可以当做一个图片一样使用 在Drawable文件夹下,创建ani ...
- android 帧动画
首先在res/drawable/name1.xml/定义一组图片集合: <?xml version="1.0" encoding="utf-8"?> ...
随机推荐
- java基础学习总结——线程(一)
一.线程的基本概念
- 解决MVC 时间序列化的方法
1.全局处理 处理代码 publict static void SetSerializationJsonFormat(HttpConfiguration config) { // Web API co ...
- Hibernate实例二
Hibernate实例二 一.测试openSession方法和getCurrentSession方法 hebernate中可以通过上述两种方法获取session对象以对数据库进行操作,下面的代码以及注 ...
- SpringBoot读取war包jar包Resource资源文件解决办法
SpringBoot读取war包jar包Resource资源文件解决办法 场景描述 在开发过程中我们经常会碰到要在代码中获取资源文件的情况,而我在最近在SpringBoot项目中时碰到一个问题,就是在 ...
- Eclipse 设置代码风格
自动调整代码风格 快捷键Ctrl + Shift + F 或者 右键 source -> format 设置代码风格 window -> preference -> java -&g ...
- LeetCode--066--加一
问题描述: 给定一个非负整数组成的非空数组,在该数的基础上加一,返回一个新的数组. 最高位数字存放在数组的首位, 数组中每个元素只存储一个数字. 你可以假设除了整数 0 之外,这个整数不会以零开头. ...
- 4-14-17 JavaScript知识点总结(包括JOSN, ajax等,来源w3c)
JavaScript 也称 ECMAScript as "JavaScript" It is designed to run as a scripting language in ...
- Vue自动化工具(Vue-CLI)
一.组件的概念 1.概念 组件(Component)是自定义封装的功能.在前端开发过程中,经常出现多个网页的功能是重复的,而且很多不同的网站之间,也存在同样的功能. 而在网页中实现一个功能,需要使用h ...
- ansible-playbook快速入门填坑
参考另外一篇文章 http://blog.51cto.com/weiweidefeng/1895261 when条件 参考http://blog.51cto.com/breezey/1757593 安 ...
- POJ-3259 Wormholes(判断负环、模板)
Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes ...