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 ...
随机推荐
- Javac源码解读-书目录
1.Javac编译器 (1)Javac编译器介绍(主要介绍如何从java源代码到class的一个转换过程) (2)Javac的源码(说明其中哪个功能由哪个主要的类来完成) (3)Javac支持的命令及 ...
- Javac之关于方法的调用1
方法的调用从Attr类的visitApply()方法进入,如下: /** Visitor method for method invocations. * NOTE: The method part ...
- [PY3]——Python的函数
Python函数总结图 1.调用 1.1 如何调用 1.1.1 函数名(传参) # 函数使用函数名来调用,函数名后紧跟一对小括号,小括号里传入函数定义时要求的参数 add(9,9) #9+9=18 ...
- 解读MySQL的慢日志
完整的慢日志格式一般如下: # Time: :: # User@Host: db_user[db_database] @ localhost [] # Query_time: Rows_examine ...
- guava快速入门(二)
Guava工程包含了若干被Google的 Java项目广泛依赖 的核心库,例如:集合 [collections] .缓存 [caching] .原生类型支持 [primitives support] ...
- Spring学习(二)--- Bean 作用域
概述 本文介绍的Spring 中bean的作用域. 问题 : bean的作用域有几种,有那些应用场景 bean 装配过程 下图为bean在容器中从创建到销毁的若干阶段. bean 作用域 作用域介绍 ...
- Cheatsheet: 2017 10.01 ~ 12.31
Mobile Updating Your App for iOS 11 Get Started With Natural Language Processing in iOS 11 Getting S ...
- 十五、curator recipes之DistributedQueue
简介 curator实现了先入先出的分布式消息队列,它采用的是zookeeper的持久化有序节点. 官方文档:http://curator.apache.org/curator-recipes/dis ...
- 字符串数组中含有json转换
[{'a':'1','b':'2'},{'c':'3','d':'4'}]" 解决 import net.sf.json.JSONArray; import net.sf.json.JSON ...
- K:大数加法
相关介绍: 在java中,整数是有最大上限的.所谓大数是指超过整数最大上限的数,例如18 452 543 389 943 209 789 324 233和8 123 534 323 432 323 ...