[翻译] RBBAnimation,让你使用关键帧动画更便利
RBBAnimation
RBBAnimation is a subclass of CAKeyframeAnimation that allows you to declare your animations using blocks instead of writing out all the individual key-frames.
This gives you greater flexibility when specifying your animations while keeping your code concise.
It comes out of the box with a replacement for CASpringAnimation, support for custom easing functions such as bouncing as well as hooks to allow your writing your own animations fully from scratch.
RBBAnimation继承自CAKeyframeAnimation,允许你在block中设置你所需要的动画属性,而不是在外面单独的写键值对。当你既想着要实现动画效果,又想保持你的代码看起来清爽,毫无疑问RBBAnimation是你不二的选择。
Installation(安装)
To install RBBAnimation, I recommend the excellent CocoaPods. Simply add this to your Podfile
pod 'RBBAnimation', '0.3.0'
and you are ready to go!
If you'd like to run the bundled test app, make sure to install its dependencies by running
pod install
after cloning the repo.
我建议你使用CocoaPods安装吧。
RBBCustomAnimation(自定义动画)
Use RBBCustomAnimation to create arbitrary animations by passing in an RBBAnimationBlock:
使用RBBCustomAnimation来创建直观的自定义动画,在RBBAnimationBlock中设置即可。

RBBCustomAnimation *rainbow = [RBBCustomAnimation animationWithKeyPath:@"backgroundColor"];
rainbow.animationBlock = ^(CGFloat elapsed, CGFloat duration) {
UIColor *color = [UIColor colorWithHue:elapsed / duration
saturation:1
brightness:1
alpha:1];
return (id)color.CGColor;
};
The arguments of the block are the current position of the animation as well as its total duration.
Most of the time, you will probably want to use the higher-level RBBTweenAnimation.
block中的参数就是你要设置动画的参数,以及需要你配置一个动画持续的时间。
大部分时间,你需要使用更高级别上的RBBTweenAnimation。
RBBSpringAnimation(精灵动画)
RBBSpringAnimation is a handy replacement for the private CASpringAnimation. Specify your spring's mass, damping, stiffness as well as its initial velocity and watch it go:
RBBSpringAnimation是用来替换这个私有方法CASpringAnimation。指定你精灵对象的质量,阻尼,生硬程度以及他的速率,参考如下:

RBBSpringAnimation *spring = [RBBSpringAnimation animationWithKeyPath:@"position.y"]; spring.fromValue = @(-100.0f);
spring.toValue = @(100.0f);
spring.velocity = 0;
spring.mass = 1;
spring.damping = 10;
spring.stiffness = 100; spring.additive = YES;
spring.duration = [spring durationForEpsilon:0.01];
RBBTweenAnimation(两点之间的动画)
RBBTweenAnimation allows you to animate from one value to another, similar to CABasicAnimation but with a greater flexibility in how the values should be interpolated.
It supports the same cubic Bezier interpolation that you get from CAMediaTimingFunction using the RBBCubicBezier helper function:
RBBTweenAnimation允许你从一个值动态变化到另外一个值,就像CABasicAnimation一样,但是呢,对于如何设置参数更加便利。
它同样支持你篡改立方体贝塞尔曲线,你可以从CAMediaTimingFunction中使用RBBCubicBezier来获取一些帮助信息:

RBBTweenAnimation *easeInOutBack = [RBBTweenAnimation animationWithKeyPath:@"position.y"]; easeInOutBack.fromValue = @(-100.0f);
easeInOutBack.toValue = @(100.0f);
easeInOutBack.easing = RBBCubicBezier(0.68, -0.55, 0.265, 1.55); easeInOutBack.additive = YES;
easeInOutBack.duration = 0.6;
However, RBBTweenAnimation also supports more complex easing functions such as RBBEasingFunctionEaseOutBounce:
当然,RBBTweenAnimation支持更复杂的easing方法,例如RBBEasingFunctionEaseOutBounce:

RBBTweenAnimation *bounce = [RBBTweenAnimation animationWithKeyPath:@"position.y"];
bounce.fromValue = @(-100);
bounce.toValue = @(100);
bounce.easing = RBBEasingFunctionEaseOutBounce; bounce.additive = YES;
bounce.duration = 0.8;
You can also specify your own easing functions, from scratch:
你也可以使用你自己定制的easiing函数:
RBBTweenAnimation *sinus = [RBBTweenAnimation animationWithKeyPath:@"position.y"];
sinus.fromValue = @(0);
sinus.toValue = @(100); sinus.easing = ^CGFloat (CGFloat fraction) {
return sin((fraction) * 2 * M_PI);
}; sinus.additive = YES;
sinus.duration = 2;

[翻译] RBBAnimation,让你使用关键帧动画更便利的更多相关文章
- 《Programming WPF》翻译 第8章 4.关键帧动画
原文:<Programming WPF>翻译 第8章 4.关键帧动画 到目前为止,我们只看到简单的点到点的动画.我们使用了To和From属性或者By属性来设计动画--相对于当前的属性值.这 ...
- Windows Store App 关键帧动画
关键帧动画和插值动画类似,同样可以根据目标属性值的变化产生相应的动画效果,不同的是,插值动画是在两个属性值之间进行渐变,而关键帧动画打破了仅通过两个属性值控制动画的局限性,它可以在任意多个属性值之间进 ...
- IOS开发-属性动画和关键帧动画的使用
CAMediaTiming是一个协议(protocol),CAAnimation是所有动画类的父类,但是它不能直接使用,应该使用它的子类. 继承关系: CoreAnmiation 核心动画 简写CA ...
- Silverlight动画的基本知识、关键帧动画
基础知识 (一)动画:是快速播放一系列图像(其中每个图像与下一个图像略微不同)给人造成的一种幻觉 (二)动画类型:两类 (1)From/To/By动画:在起始值和结束值之间进行动画处理. ...
- Windows Phone开发(41):漫谈关键帧动画之下篇
原文:Windows Phone开发(41):漫谈关键帧动画之下篇 也许大家已经发现,其实不管什么类型的动画,使用方法基本是一样的,不知道大家总结出规律了没有?当你找到规律之后,你会发现真的可以举一反 ...
- Windows Phone开发(39):漫谈关键帧动画上篇
原文:Windows Phone开发(39):漫谈关键帧动画上篇 尽管前面介绍的几种动画会让觉得很好玩了,但是,不知道你是否发现,在前面说到的一系列XXXAnimation中,都有一个共同点,那就是仅 ...
- Core Animation中的关键帧动画
键帧动画就是在动画控制过程中开发者指定主要的动画状态,至于各个状态间动画如何进行则由系统自动运算补充(每两个关键帧之间系统形成的动画称为“补间动画”),这种动画的好处就是开发者不用逐个控制每个动画帧, ...
- ios基础动画、关键帧动画、动画组、转场动画等
概览 在iOS中随处都可以看到绚丽的动画效果,实现这些动画的过程并不复杂,今天将带大家一窥iOS动画全貌.在这里你可以看到iOS中如何使用图层精简非交互式绘图,如何通过核心动画创建基础动画.关键帧动画 ...
- WPF中的动画——(五)关键帧动画
与 From/To/By 动画类似,关键帧动画以也可以以动画形式显示目标属性值. 和From/To/By 动画不同的是, From/To/By 动画只能控制在两个状态之间变化,而关键帧动画则可以在多个 ...
随机推荐
- Rookey.Frame之菜单设置
在上一篇博文 Rookey.Frame企业级快速开发框架开源了 中我们介绍了Rookey.Frame极速开发框架的最新更新及开源介绍,后面慢慢介绍该框架的使用方法,本人文笔不好,写得不够好的地方请大家 ...
- USACO 6.4 Electric Fences
Electric FencesKolstad & Schrijvers Farmer John has decided to construct electric fences. He has ...
- USACO 5.3 Network of Schools
Network of SchoolsIOI '96 Day 1 Problem 3 A number of schools are connected to a computer network. A ...
- spring调用方法(接口和多个实现类的情况)
以spring框架注入bean说明接口TestService 有2个实现类 TestServiceImp1 @Service("TestService1") ,TestServic ...
- 12:输出1到n位最大整数
如果按照最简单的循环输出,会遇到边界问题,n非常大的话,int甚至long都不能满足需求,所以这里需要用数组或者是字符串来表示要输出的数字. 如果面试题给定了一个n位整数,那么就是大数问题,用字符串来 ...
- php读取文件内容的4钟常用方法函数
这四种方法根据不同情况使用,可以实现对文件的任何操作,下面有详细介绍. 1.把整个文件读入一个字符串中 file_get_contents(); 2.把整个文件读入一个数组中,一行就是一个数组元素 f ...
- HDU - 1022 Train Problem I STL 压栈
Train Problem I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- 【基础知识】ASP.NET[基础一(ashx)]
一.ASP.NET介绍 1.ASP.NET包括: 一般处理程序(ashx):WebForm ( aspx ):MVC(Model view con~~): 2.ASP.NET的常用文件(重点): 1& ...
- [leetcode DP]53. Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest ...
- 【SQL】177. Nth Highest Salary
Write a SQL query to get the nth highest salary from the Employee table. +----+--------+ | Id | Sala ...
