GithubHelp home page GithubHelp logo

agens-no / anymotion Goto Github PK

View Code? Open in Web Editor NEW
33.0 7.0 9.0 13.54 MB

one unified API for animating UIKit, CoreAnimation, POP and your library of choice.

License: Other

Objective-C 78.86% Ruby 0.49% C 19.26% Swift 1.40%

anymotion's Introduction

Screenshot

Anymotion provides one unified API for animating UIKit, CoreAnimation, POP and your library of choice

  • powerful oneliners
  • grouping and chaining animations
  • cancellable animations with callbacks for clean up
  • swift api

Installation

Via CocoaPods

If you're using CocoaPods, you can simply add to your Podfile:

pod 'Anymotion', :git => 'https://github.com/agens-no/Anymotion.git', :branch => 'master'

This will download the Anymotion and dependencies in Pods/ during your next pod install exection. You may have to say pod repo update first.

Import in swift
import Anymotion
Import in Objective-C
#import <Anymotion/Anymotion.h>
Via Carthage

To install via Carthage add to your Cartfile:

github "agens-no/anymotion"
Import in swift
import Anymotion
Import in Objective-C
#import <Anymotion/Anymotion.h>

Basics

Using a chainable builder pattern we can pack a good deal of configuration in one line

let goRight = ANYPOPSpring(kPOPLayerPositionX).toValue(100).springSpeed(5).animation(for: view.layer)
let fadeOut = ANYCABasic(#keyPath(CALayer.opacity)).toValue(0).duration(1).animation(for: view.layer)

Note: These animations won't start unless you say start like this

goRight.start()
fadeOut.start()
GIF

Instead of starting each one individually you can group them

goRight.groupWith(fadeOut).start()
GIF

Calling start actually returns an ANYActivity empowering you to stop the animation at any time.

let activity = goRight.groupWith(fadeOut).start()
...
activity.cancel()
GIF

Live Examples

Compile and run the iOS-Example project to watch some beautiful examples!

GIF

GIF

GIF

Frameworks integrations

POP

let spring = ANYPOPSpring(kPOPLayerPositionX)
               .toValue(100)
               .springSpeed(5)
               .animation(for: view.layer)
GIF
let basic = ANYPOPBasic(kPOPLayerPositionX)
               .toValue(100)
               .duration(2)
               .animation(for: view.layer)
GIF
let decay = ANYPOPDecay(kPOPLayerPositionX)
               .velocity(10)
               .animation(for: view.layer)
GIF

Core Animation

let basic = ANYCABasic(#keyPath(CALayer.position))
               .toValue(CGPoint(x: 100, y: 0))
               .duration(2)
               .animation(for: view.layer)
GIF

UIKit

let uikit = ANYUIView.animation(duration: 2) {
    view.center.x = 100
}
GIF

Operators

Grouping

Start animations simultaneously

ANYAnimation *goRight = ...;
ANYAnimation *fadeOut = ...;
ANYAnimation *group = [ANYAnimation group:@[goRight, fadeOut]];
[group start];
GIF

Chaining

When one animation completes then start another

ANYAnimation *goRight = ...;
ANYAnimation *goLeft = ...;
ANYAnimation *group = [goRight then:goLeft];
[group start];
GIF

Repeat

ANYAnimation *goRight = ...;
ANYAnimation *goLeft = ...;
ANYAnimation *group = [[goRight then:goLeft] repeat];
[group start];
GIF

Set up and clean up

ANYAnimation *pulsatingDot = ...;
[[pulsatingDot before:^{
   view.hidden = NO;
}] after:^{
   view.hidden = YES;
}];
[pulsatingDot start];
GIF

Callbacks

ANYAnimation *anim = ...;
[[anim onCompletion:^{
    NSLog(@"Animation completed");
} onError:^{
    NSLog(@"Animation was cancelled");
}] start];
GIF

Feedback

We would 😍 to hear your opinion about this library. Wether you like it or don't. Please file an issue if there's something you would like like improved, so we can fix it!

If you use Anymotion and are happy with it consider sending out a tweet mentioning @agens. This library is made with love by Mats Hauge, who's passionate about animations, and Håvard Fossli, who cares deeply about architecture.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.