[翻译] POP Facebook的动画开源库

Pop is an extensible animation engine for iOS and OS X. In addition to basic static animations, it supports spring and decay dynamic animations, making it useful for building realistic, physics-based interactions. The API allows quick integration with existing Objective-C codebases and enables the animation of any property on any object. It's a mature and well-tested framework that drives all the animations and transitions in Paper.
Pop是一个对iOS以及OS X扩展的动画引擎。除了基础静态的动画,它支持弹簧类以及衰退的物理引擎效果的动画。对于你来创建出类似于物理引擎的交互十分方便。这个API能让你快速的集成到你已经存在的项目当中,允许你对任何对象的任何属性操作。他是个系统的,进行过反复测试的框架,在Paper应用中所有的动画均由Pop创建。
Installation
Pop is available on CocoaPods. Just add the following to your project Podfile:
你可以使用CocoaPods安装:
pod 'pop', '~> 1.0'
Alternatively, you can add the project to your workspace and adopt the provided configuration files or manually copy the files under the pop subdirectory into your project. If installing manually, ensure the C++ standard library is also linked by including -lc++ to your project linker flags.
另一种方式是:你可以将整个工程添加到你的workspace中然后引用需要的配置文件,或者是手动的复制pop文件夹到你的工程项目当中,确保你的项目中用 -lc++ 链接到C++标准库。
Usage
Pop adopts the Core Animation explicit animation programming model. Use by including the following import:
Pop 采用了 Core Animation 明确的动画程勋模型,通过引入头文件来使用:
#import <POP/POP.h>
Start, Stop & Update
To start an animation, add it to the object you wish to animate:
为了给对象添加动画效果,使用如下:
POPSpringAnimation *anim = [POPSpringAnimation animation];
...
[layer pop_addAnimation:anim forKey:@"myKey"];
To stop an animation, remove it from the object referencing the key specified on start:
为了停止动画,你可以从指定的key值,从对象移除掉:
[layer pop_removeAnimationForKey:@"myKey"];
The key can also be used to query for the existence of an animation. Updating the toValue of a running animation can provide the most seamless way to change course:
这个key值也可以用来查询已经存在的动画。更新 toValue 值可以无缝的更新动画的流程:
anim = [layer pop_animationForKey:@"myKey"];
if (anim) {
/* update to value to new destination */
anim.toValue = @(42.0);
} else {
/* create and start a new animation */
....
}
While a layer was used in the above examples, the Pop interface is implemented as a category addition on NSObject. Any NSObject or subclass can be animated.
上例中使用了一个layer,然而,Pop是通过对NSObject的category实现方式。任何的NSObject或者其只对象都能够使用动画。
Types
There are four concrete animation types: spring, decay, basic and custom.
有着4种具体的动画类型:弹簧类型,衰退的物理引擎类型,基础类型以及定制类型。
Spring animations can be used to give objects a delightful bounce. In this example, we use a spring animation to animate a layer's bounds from its current value to (0, 0, 400, 400):
弹簧动画效果可以给对象一个很平滑的动画效果。使用如下例子所示:
POPSpringAnimation *anim = [POPSpringAnimation animationWithPropertyNamed:kPOPLayerBounds];
anim.toValue = [NSValue valueWithCGRect:CGRectMake(0, 0, 400, 400)];
[layer pop_addAnimation:anim forKey:@"size"];
Decay animations can be used to gradually slow an object to a halt. In this example, we decay a layer's positionX from it's current value and velocity 1000pts per second:
类似于物理引擎的动画可以慢慢将一个对象从运动状态变为停止状态。使用如下例子所示:
POPDecayAnimation *anim = [POPDecayAnimation animationWithPropertyNamed:kPOPLayerPositionX];
anim.velocity = @(1000.);
[layer pop_addAnimation:anim forKey:@"slide"];
Basic animations can be used to interpolate values over a specified time period. To use an ease-in ease-out animation to animate a view's alpha from 0.0 to 1.0 over the default duration:
基本动画类型可以用来篡改一个指定的时间区域。使用如下例子:
POPBasicAnimation *anim = [POPBasicAnimation animationWithPropertyNamed:kPOPViewAlpha];
anim.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
anim.fromValue = @(0.0);
anim.toValue = @(1.0);
[view pop_addAnimation:anim forKey:@"fade"];
POPCustomAnimation makes creating custom animations and transitions easier by handling CADisplayLink and associated time-step management. See header for more details.
POPCustomAnimation 通过控制CADisplayLink以及与时间轴的管理,使得创建自定义动画以及转场更加的简单,你可以在头文件中浏览。
Properties
The property animated is specified by the POPAnimatableProperty class. In this example we create a spring animation and explicitly set the animatable property corresponding to -[CALayer bounds]:
用来触发动画的类是POPAnimatableProperty。这个例子中,我们创建了一个弹簧动画,以及明确的设定了这个动画来响应-[CALayer bounds]:
POPSpringAnimation *anim = [POPSpringAnimation animation];
anim.property = [POPAnimatableProperty propertyWithName:kPOPLayerBounds];
The framework provides many common layer and view animatable properties out of box. You can animate a custom property by creating a new instance of the class. In this example, we declare a custom volume property:
这个框架提供了很多种通用的layer以及可以被动画的view的属性。你可以通过创建一个实例来自定义一个可以动画的属性。以下例子提供了如何让音量属性动画改变:
prop = [POPAnimatableProperty propertyWithName:@"com.foo.radio.volume" initializer:^(POPMutableAnimatableProperty *prop) {
// read value
prop.readBlock = ^(id obj, CGFloat values[]) {
values[0] = [obj volume];
};
// write value
prop.writeBlock = ^(id obj, const CGFloat values[]) {
[obj setVolume:values[0]];
};
// dynamics threshold
prop.threshold = 0.01;
}];
anim.property = prop;
For a complete listing of provided animatable properties, as well more information on declaring custom properties see POPAnimatableProperty.h.
请参考POPAnimatableProperty.h来获取一份完整的可以提供动画完整的属性列表。
Debugging
Here are a few tips when debugging. Pop obeys the Simulator's Toggle Slow Animations setting. Try enabling it to slow down animations and more easily observe interactions.
Consider naming your animations. This will allow you to more easily identify them when referencing them, either via logging or in the debugger:
anim.name = @"springOpen";
Each animation comes with an associated tracer. The tracer allows you to record all animation-related events, in a fast and efficient manner, allowing you to query and analyze them after animation completion. The below example starts the tracer and configures it to log all events on animation completion:
POPAnimationTracer *tracer = anim.tracer;
tracer.shouldLogAndResetOnCompletion = YES;
[tracer start];
See POPAnimationTracer.h for more details.
Testing
Pop has extensive unit test coverage. To install test dependencies, navigate to the root pop directory and type:
pod install
Assuming CocoaPods is installed, this will include the necessary OCMock dependency to the unit test targets.
Resources
A collection of links to external resources that may prove valuable:
- Apple – Core Animation Programming Guide
- Tapity Tutorial – Getting Started with Pop
- Codeplease – Bridging the gesture to animation gap
- Codeplease – Playing with Pop (iii)
- Codeplease – Adding a custom animatable property
- Pop Playground – Repository of Pop animation examples
- POP-MCAnimate – Concise syntax for the Pop animation framework
- Tweaks – Easily adjust parameters for iOS apps in development
- Rebound – Spring Animations for Android
Contributing
See the CONTRIBUTING file for how to help out.
License
Pop is released under a BSD License. See LICENSE file for details.
[翻译] POP Facebook的动画开源库的更多相关文章
- Lottie开源库实现Android动画效果
Lottie简介 Lottie是一个支持Android.iOS.React Native,并由Adobe After Effects制作aep格式的动画,然后经由bodymovin插件转化渲染为jso ...
- ios很好的开源库
Tim9Liu9/TimLiu-iOS 自己总结的iOS.mac开源项目及库,持续更新.. 目录 UI 下拉刷新 模糊效果 AutoLayout 富文本 图表 表相关与Tabbar 隐藏与显示 HUD ...
- IOS 第三方开源库记录
网易客户端使用 1.ZipArchive 2.wax 3.TTTAttributedLabel 4.SSKeychain 5.SDWebImage 6.RegexKitLite 7.pop 8.NJK ...
- 33 个 2017 年必须了解的 iOS 开源库
本文翻译自Medium,原作者为Pawe? Bia?ecki 照片版权:(Unsplash/Markus Pe) 你好,iOS 开发者们!我的名字叫 Pawe?,我是一个独立 iOS 开发者,并且是 ...
- Android开源库项目集锦
一.兼容类库 ActionBarSherlock : Action Bar是Android 3.0后才開始支持的,ActionBarSherlock是让Action Bar功能支持2.X后的全部平台. ...
- 33 个 2017 年必须了解的 iOS/swift 开源库第三方库
本文翻译自Medium,原作者为 Paweł Białecki<img src="https://pic3.zhimg.com/v2-c786777447261347b0d97 ...
- 各种Android UI开源框架 开源库
各种Android UI开源框架 开源库 转 https://blog.csdn.net/zhangdi_gdk2016/article/details/84643668 自己总结的Android开源 ...
- 开源框架】Android之史上最全最简单最有用的第三方开源库收集整理,有助于快速开发
[原][开源框架]Android之史上最全最简单最有用的第三方开源库收集整理,有助于快速开发,欢迎各位... 时间 2015-01-05 10:08:18 我是程序猿,我为自己代言 原文 http: ...
- 100个Github上Android开源库
项目名称 项目简介 1. react-native 这个是 Facebook 在 React.js Conf 2015 大会上推出的基于 JavaScript 的开源框架 React Native, ...
随机推荐
- Hive入门学习随笔(一)
Hive入门学习随笔(一) ===什么是Hive? 它可以来保存我们的数据,Hive的数据仓库与传统意义上的数据仓库还有区别. Hive跟传统方式是不一样的,Hive是建立在Hadoop HDFS基础 ...
- MINIBASE源代码阅读笔记之heapfile
Heapfile 用来管理heap file里的dir page们 成员 _firstDirPageId:这个文件的第一个dir page _ftype:文件类型 _file_deleted:删除的时 ...
- 【PAT】1007. 素数对猜想 (20)
1007. 素数对猜想 (20) 让我们定义 dn 为:dn = pn+1 - pn,其中 pi 是第i个素数.显然有 d1=1 且对于n>1有 dn 是偶数.“素数对猜想”认为“存在无穷多对相 ...
- ThinkPHP 多语言的实现
1.按照官方文档进行修改 2.注意区分项目语言包和系统语言包 3.实现语言包和数据库语言同步切换 4.thinkPHP多语言实现与Cookie有关, 谷歌浏览器下按F12查看Request Heade ...
- 559. N叉树的最大深度
给定一个 N 叉树,找到其最大深度. 最大深度是指从根节点到最远叶子节点的最长路径上的节点总数. 例如,给定一个 3叉树 : 我们应返回其最大深度,3. 说明: 树的深度不会超过 1000. 树的节点 ...
- 牛客练习赛9 B - 珂朵莉的值域连续段
题目描述 珂朵莉给你一个有根树,求有多少个子树满足其内部节点编号在值域上连续 一些数在值域上连续的意思即其在值域上构成一个连续的区间 输入描述: 第一行有一个整数n,表示树的节点数.接下来n–1行,每 ...
- java8新特性——接口中的静态方法与默认方法
以前我们知道,接口中的方法必须时抽象方法,而从 java8 开始接口中也可以有方法的实现了,叫做默认方法. 一 .默认方法(default修饰) 在 java8 中,因为存在函数式接口,一个接口中只能 ...
- 【BZOJ 3997】 3997: [TJOI2015]组合数学 (DP| 最小链覆盖=最大点独立集)
3997: [TJOI2015]组合数学 Time Limit: 20 Sec Memory Limit: 128 MBSubmit: 919 Solved: 664 Description 给出 ...
- Linux下解压缩 - 中文解决方案
命令行工具 Unar 以及 Lsar 安装:sudo apt-get install unar: 预览压缩包:lsar example.zip 解压缩:unar example.zip 指定位置解压: ...
- [BZOJ3583]杰杰的女性朋友(矩阵快速幂)
杰杰的女性朋友 时间限制:10s 空间限制:256MB 题目描述 杰杰是魔法界的一名传奇人物.他对魔法具有深刻的洞察力,惊人的领悟力,以及令人叹为观止的创造力.自从他从事魔法竞赛以来,短短几 ...