• Stars
    star
    2,061
  • Rank 22,431 (Top 0.5 %)
  • Language
    Objective-C
  • License
    MIT License
  • Created about 11 years ago
  • Updated over 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

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

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.

Installation

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

pod '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

pod install

after cloning the repo.

RBBCustomAnimation

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

Rainbow

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.

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

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:

Ease In Out Back

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:

Bouncing

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:

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;

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.

More Repositories

1

Cartography

A declarative Auto Layout DSL for Swift 📱📐
Swift
7,338
star
2

hamburger-button

A hamburger button transition
Swift
2,308
star
3

Underscore.m

A DSL for Data Manipulation
Objective-C
1,465
star
4

FLXView

A UIView that uses Flexbox for layouting. ✨
Objective-C
481
star
5

Swim

A DSL for writing HTML in Swift
Swift
310
star
6

Asterism

Asterism is yet another functional toolbelt for Objective-C. It tries to be typesafe and simple.
Objective-C
226
star
7

RBBJSON

Flexible JSON traversal for rapid prototyping.
Swift
164
star
8

Fantastical-Alfred-Workflow

A simple Alfred 2 workflow for Fantastical.
158
star
9

NES.swift

An NES emulator written in Swift
Swift
149
star
10

dotfiles

Dotfiles to make computing personal.
Shell
87
star
11

Stubbilino

Simple stubbing for Objective-C
Objective-C
86
star
12

swamp

icon stamping in Swift
Swift
85
star
13

Peel-Off-Animation-Example-Code

Example code for https://robb.is/working-on/a-peel-off-animation
Swift
62
star
14

Monocle

Pretty much only a Lens
Swift
45
star
15

ShaderBugs

Some isssues I ran into with SwiftUI.Shader
Swift
36
star
16

robb.swift

My personal website ported to Swift
Swift
34
star
17

Xcode-Configurations

Useful tweaks to Xcode
Objective-C
30
star
18

jekyll-embedly-client

No longer maintained
Ruby
23
star
19

URLRequest-AWS

An extension on URLRequest to sign it for AWS.
Swift
20
star
20

Marbleo.us

A marbleous project
CoffeeScript
18
star
21

Digitale-Zivilgesellschaft

Recommendations from multiple civil society organisations that fight for independent digital infrastructure and open access to knowledge.
HTML
11
star
22

laughing-man

The Laughing Man logo implemented in pure HTML/CSS
6
star
23

monome.js

A library for writing monome apps with node.js
C++
5
star
24

slang

The pxl effect in the browser
CoffeeScript
4
star
25

spinamp

Winamp inside Spotify – it really whips the moose's ass
CoffeeScript
2
star
26

FeedImporter

Import RSS feeds into SoundCloud
Ruby
1
star
27

thedickensbar.com

Put a Dickensbar on top of every page. Lost all its meaning now that the dickbar is gone…
CSS
1
star
28

6strings

Guitar synthesis in the browser!
CoffeeScript
1
star
29

Future

A simple, cold Future.
Swift
1
star