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 ...
随机推荐
- Linux 进程以及多线程的支持
1.最初内核并没有实现对多线程的支持,2.6之后开始以轻量级进程的方式对多线程进行支持(轻量级线程组). a.在2.6 之前,如果需要实现多线程,只能在用户态下实现,用户程序自己控制线程的切换, 实际 ...
- JavaScript设计模式-14.组合模式实现
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...
- 使用jdk生成ssl证书文件
java自带有 ssl 证书生成的工具, 在 /bin/keytools.exe 需要确认已经正确配置JAVA_HOME的环境变量 生成服务端证书: keytool -genkey -v -alias ...
- zsh: command not found: gulp
明明安装了gulp,但是为什么执行gulp命令却在控制台输出 zsh: command not found: gulp 可能因为gulp没有被全局安装 在控制台输入 which gulp 如果输出 g ...
- java读取项目或包下面的属性文件方法
1.使用java.util.Properties类的load()方法 //文件在项目下.不是在包下!! InputStream in = new BufferedInputStream(newFile ...
- 1、类、封装(私有private、this关键字)
类与对象 对象在需求中的使用 对面向对象有了了解之后,我们来说说在具体问题中如何使用面向对象去分析问题,和如何使用面向对象. 我们把大象装冰箱为例进行分析. 在针对具体的需求,可以使用名词 ...
- spring中AOP的AspectJ的Execution表达式
AspectJ的Execution表达式: 使用springAOP定义pointcut里面的execution表达式: execution()函数是常用的切点函数 "execution(* ...
- Hunger Snake
除了驱动的效果.
- NIO与Socket
一.Socket 的使用 1.单线程Socket的使用 /** * 单线程版本 * 问题描述:只能服务单个客户端 * 解决方案:多线程版本 */ public class Socket_V1 { pu ...
- 搞懂WebSocket原理
一.websocket与http WebSocket是HTML5出的东西(协议),也就是说HTTP协议没有变化,或者说没关系,但HTTP是不支持持久连接的(长连接,循环连接的不算) 首先HTTP有 1 ...