POP动画[3]
POP动画[3]

这一节主要讲解POP动画的自定义动画属性.
POP动画中有一个参数,叫timingFunction,与CoreAnimation中的一个参数CAMediaTimingFunction基本一样,下图表示的是kCAMediaTimingFunctionEaseInEaseOut的曲线图.


下图是Spring动画效果:

我们可以使用自定义的属性来实现POP的库中没有提供的动画.
实现的效果:

源码:
//
// RootViewController.m
// YXPOP
//
// Copyright (c) 2014年 Y.X. All rights reserved.
// #import "RootViewController.h"
#import "POP.h" @interface RootViewController () @end @implementation RootViewController - (void)viewDidLoad
{
[super viewDidLoad];
self.view.backgroundColor = [UIColor blackColor]; // 数值型label
UILabel *numberLabel = [[UILabel alloc] initWithFrame:CGRectMake(, , , )];
numberLabel.center = self.view.center;
numberLabel.userInteractionEnabled = YES;
numberLabel.textAlignment = NSTextAlignmentCenter;
numberLabel.textColor = [UIColor redColor];
numberLabel.text = @"";
numberLabel.font = [UIFont fontWithName:@"HelveticaNeue-UltraLight"
size:.f];
[self.view addSubview:numberLabel]; // 添加手势
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(tap:)];
[numberLabel addGestureRecognizer:tap]; } - (void)tap:(UITapGestureRecognizer *)tap
{
UILabel *tmp = (UILabel *)tap.view;
POPBasicAnimation *animation = [POPBasicAnimation animation];
animation.fromValue = @([tmp.text intValue]);
animation.toValue = @(arc4random()% + );
animation.duration = .f; // 计算从fromValue到toValue插值的曲线
animation.timingFunction = \
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; // 将计算出来的值通过writeBlock动态给控件设定
animation.property = \
[POPMutableAnimatableProperty propertyWithName:@"textLabel" initializer:^(POPMutableAnimatableProperty *prop) {
prop.writeBlock = ^(id obj, const CGFloat values[]) {
UILabel *label = (UILabel *)obj;
NSNumber *number = @(values[]);
int num = [number intValue];
label.text = [@(num) stringValue];
};
}]; [tmp pop_addAnimation:animation forKey:@"numberLabelAnimation"];
} @end
他们彼此间凌乱的关系如下所示:
duration代表x轴(时间轴)
fromValue与toValue代表y轴的最小值与最大值
timingFunction代表时间曲线(EaseOut曲线)
曲线中的每一个小点代表的是根据上述各个值计算出来的一个中间值,而这个中间值就是我们用来做动画而用的动画设定值.

以下网址是介绍如何设定CAMediaTimingFunction的(http://netcetera.org/camtf-playground.html).
POP动画[3]的更多相关文章
- iOS动画——弹窗动画(pop动画)
用pop动画简单实现弹窗的缩放和渐变,感觉这个动画常用,就写一下博客 pop动画是Facebook推出的动画引擎,请自行到GitHub上搜索下载拖拽导入xcode项目中. 更多pop动画使用和原理可网 ...
- 用POP动画引擎实现衰减动画(POPDecayAnimation)
效果图: #import "ViewController.h" #import <POP.h> @interface ViewController () @end @i ...
- POP动画引擎中Layer与CALayer的一点区别
POP动画引擎是facebook提供的一个开源框架, 可以实现很多的动画效果, 这里就不一一介绍啦, 有兴趣的童鞋请移步: https://github.com/facebook/pop 下面简单的讲 ...
- 用POP动画编写带富文本的自定义动画效果
用POP动画编写带富文本的自定义动画效果 [源码] https://github.com/YouXianMing/UI-Component-Collection [效果] [特点] * 支持富文本 * ...
- POP动画[1]
POP动画[1] pop动画是facebook扩展CoreAnimation的,使用及其方便:) 1:Spring系列的弹簧效果(两个动画kPOPLayerBounds与kPOPLayerCorner ...
- 用POP动画模拟真实秒钟摆动效果
用POP动画模拟真实秒钟摆动效果 静态图: 动画图: 此处用到了POP中的Spring系列动画,现提供源码如下: SecondClockView.h 与 SecondClockView.m // // ...
- POP动画[2]
POP动画[2] 1:定制控制器间的转场动画. 源码有点多-_-!! // // RootViewController.h // Animation // // Copyright (c) 2014年 ...
- 自定义UINavigationController push和pop动画
http://segmentfault.com/q/1010000000143983 默认的UINavigationController push和pop的默认动画都是左右滑动推出,我的应用要求这种界 ...
- 转 脸书pop动画的五个步骤
http://blog.csdn.net/u013741809/article/details/38511741 5 Steps For Using Facebook Pop // 1. Pick ...
随机推荐
- tp5 数据库相关操作笔记
这里如何连接多个数据库? 1,在conif.php文件中添加一个数据库配置(把database.php文件内容复制一份过来),这里取名为db2 2,在控制器的方法中使用 mysql中的参数绑定 mys ...
- Set up the environment for driver compiling in Debian
1.check the kernel version $ uname -r --amd64 2.install the source code $ sudo apt-get install linux ...
- PHP之mb_internal_encoding使用
mb_internal_encoding (PHP 4 >= 4.0.6, PHP 5, PHP 7) mb_internal_encoding - Set/Get internal chara ...
- RabbitMQ的安装和配置化可视界面
RabbitMQ在windows下的安装 RabbitMQ 它依赖于Erlang,在window上安装时,需要先安装Erlang. 首先确定你的window电脑是32位还是64位,然后下载对应版本的E ...
- Gradle中的SourceSet理解
对于maven项目来说,目录结构是固定的,也就是像这样: src/main/ src/main/java/ src/main/resources/ src/test/ src/test/java/ s ...
- 你不知道的https工作原理
HTTPS其实是有两部分组成:HTTP + SSL / TLS,也就是在HTTP上又加了一层处理加密信息的模块.服务端和客户端的信息传输都会通过TLS进行加密,所以传输的数据都是加密后的数据 1. ...
- 进度监视器--ProgressMonitorInputStream
进度监视器--ProgressMonitorInputStream ProgressMonitorInputStream 可以创建一个进度监视器,以监视读取输入流的进度.如果需要一段时间,将会弹出 P ...
- ZOJ Problem Set - 2818
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1818 一开始想着用循环做,看了别人的解法才发现根本没必要,比较根号n就行了 # ...
- NIO与Socket
一.Socket 的使用 1.单线程Socket的使用 /** * 单线程版本 * 问题描述:只能服务单个客户端 * 解决方案:多线程版本 */ public class Socket_V1 { pu ...
- equals、==和hashCode
equals和== ==可以用于基本类型和引用类型:当用于基本类型时,比较值是否相同:当用于引用类型时,比较的是所指向的对象的地址是否相同.如果有包装类型,则先将包装类型转换为基本类型再比较值是否相等 ...