wireapp/RBBAnimation

Name: RBBAnimation

Owner: Wire Swiss GmbH

Description: Block-based animations made easy, comes with easing functions and a CASpringAnimation replacement.

Forked from: wearezeta/RBBAnimation

Created: 2016-07-14 14:42:39.0

Updated: 2016-09-07 06:42:00.0

Pushed: 2015-10-09 15:35:32.0

Homepage:

Size: 195

Language: Objective-C

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

RBBAnimation

<img src="https://travis-ci.org/robb/RBBAnimation.svg?branch=master" align="right">

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.

Installation

To install RBBAnimation, I recommend the excellent CocoaPods. Simply add this to your Podfile

'RBBAnimation', '0.4.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

install

after cloning the repo.

RBBCustomAnimation

Use RBBCustomAnimation to create arbitrary animations by passing in an RBBAnimationBlock:

Rainbow

ustomAnimation *rainbow = [RBBCustomAnimation animationWithKeyPath:@"backgroundColor"];

bow.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.

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:

Bouncing

pringAnimation *spring = [RBBSpringAnimation animationWithKeyPath:@"position.y"];

ng.fromValue = @(-100.0f);
ng.toValue = @(100.0f);
ng.velocity = 0;
ng.mass = 1;
ng.damping = 10;
ng.stiffness = 100;

ng.additive = YES;
ng.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:

Ease In Out Back

weenAnimation *easeInOutBack = [RBBTweenAnimation animationWithKeyPath:@"position.y"];

InOutBack.fromValue = @(-100.0f);
InOutBack.toValue = @(100.0f);
InOutBack.easing = RBBCubicBezier(0.68, -0.55, 0.265, 1.55);

InOutBack.additive = YES;
InOutBack.duration = 0.6;

However, RBBTweenAnimation also supports more complex easing functions such as RBBEasingFunctionEaseOutBounce:

Bouncing

weenAnimation *bounce = [RBBTweenAnimation animationWithKeyPath:@"position.y"];
ce.fromValue = @(-100);
ce.toValue = @(100);
ce.easing = RBBEasingFunctionEaseOutBounce;

ce.additive = YES;
ce.duration = 0.8;

You can also specify your own easing functions, from scratch:

weenAnimation *sinus = [RBBTweenAnimation animationWithKeyPath:@"position.y"];
s.fromValue = @(0);
s.toValue = @(100);

s.easing = ^CGFloat (CGFloat fraction) {
return sin((fraction) * 2 * M_PI);


s.additive = YES;
s.duration = 2;

Sine Wave

License

RBBAnimation was built by Robert Böhnke. It is licensed under the MIT License.

If you use RBBAnimation in one of your apps, I'd love to hear about it. Feel free to follow me on Twitter where I'm @ceterum_censeo.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.