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]的更多相关文章

  1. iOS动画——弹窗动画(pop动画)

    用pop动画简单实现弹窗的缩放和渐变,感觉这个动画常用,就写一下博客 pop动画是Facebook推出的动画引擎,请自行到GitHub上搜索下载拖拽导入xcode项目中. 更多pop动画使用和原理可网 ...

  2. 用POP动画引擎实现衰减动画(POPDecayAnimation)

    效果图: #import "ViewController.h" #import <POP.h> @interface ViewController () @end @i ...

  3. POP动画引擎中Layer与CALayer的一点区别

    POP动画引擎是facebook提供的一个开源框架, 可以实现很多的动画效果, 这里就不一一介绍啦, 有兴趣的童鞋请移步: https://github.com/facebook/pop 下面简单的讲 ...

  4. 用POP动画编写带富文本的自定义动画效果

    用POP动画编写带富文本的自定义动画效果 [源码] https://github.com/YouXianMing/UI-Component-Collection [效果] [特点] * 支持富文本 * ...

  5. POP动画[1]

    POP动画[1] pop动画是facebook扩展CoreAnimation的,使用及其方便:) 1:Spring系列的弹簧效果(两个动画kPOPLayerBounds与kPOPLayerCorner ...

  6. 用POP动画模拟真实秒钟摆动效果

    用POP动画模拟真实秒钟摆动效果 静态图: 动画图: 此处用到了POP中的Spring系列动画,现提供源码如下: SecondClockView.h 与 SecondClockView.m // // ...

  7. POP动画[2]

    POP动画[2] 1:定制控制器间的转场动画. 源码有点多-_-!! // // RootViewController.h // Animation // // Copyright (c) 2014年 ...

  8. 自定义UINavigationController push和pop动画

    http://segmentfault.com/q/1010000000143983 默认的UINavigationController push和pop的默认动画都是左右滑动推出,我的应用要求这种界 ...

  9. 转 脸书pop动画的五个步骤

    http://blog.csdn.net/u013741809/article/details/38511741 5 Steps For Using Facebook Pop   // 1. Pick ...

随机推荐

  1. 在Ubuntu16.04集群上手工部署Kubernetes

    目前Kubernetes为Ubuntu提供的kube-up脚本,不支持15.10以及16.04这两个使用systemd作为init系统的版本. 这里详细介绍一下如何以非Docker方式在Ubuntu1 ...

  2. 对于SQL Server 2008删除或压缩数据库日志的方法

    由于数据库日志增长被设置为“无限制”,所以时间一长日志文件必然会很大,一个400M的数据库居然有4G的LOG文件,严重占用了磁盘空间.由于主要是做OLAP,所以数据库本身不会有大变动,所以日志也就没有 ...

  3. PHP之mb_strrpos使用

    mb_strrpos (PHP 4 >= 4.0.6, PHP 5, PHP 7) mb_strrpos - Find position of last occurrence of a stri ...

  4. 09 jdk1.5的并发容器:CopyOnWriteArrayList(转载)

    原文链接:http://ifeve.com/java-copy-on-write/ Copy-On-Write简称COW,是一种用于程序设计中的优化策略. 其基本思路是,从一开始大家都在共享同一个内容 ...

  5. guava快速入门(一)

    Guava工程包含了若干被Google的 Java项目广泛依赖 的核心库,例如:集合 [collections] .缓存 [caching] .原生类型支持 [primitives support] ...

  6. C# 多维数组

    int[, ,] shuzu = new int[4, 3, 2]; //有四个二维数组,每个二维数组里面有3个1维数组,每个1维数组里面有2个元素

  7. Java 双亲委派模型

    1. Java 类加载器的分类 2. 双亲委派模型 Parents Delegration Model

  8. 解决:IDEA springmvc maven 项目搭建完后没有生成 webcontent 目录

    前言:发现项目创建好,配置好,写好测试代码,一看没有 webcontent 目录. 问题: 解决方案: ctrl + alt + Shift + S

  9. K:线性表的实现—顺序表

    所谓顺序表,就是顺序存储的线性表.顺序存储就是用一组地址连续的存储单元依次存放线性表中各个数据元素的存储结构. 线性表中所有数据元素的类型是相同的,所以每一个数据元素在存储器中占用相同的大小的空间.假 ...

  10. Python Djan 路由对应的名称

    路由关系命名 对URL路由关系进行命名,以后可以根据此名称生成自己想要的URL 1. url(r'fdsafdsaeeeee',views.index, name='hello') #给这个url后面 ...