Giter Site home page Giter Site logo

jnwspringanimation's Introduction

JNWSpringAnimation

JNWSpringAnimation is a subclass of CAKeyframeAnimation that adds support for creating damped harmonic animations.

Getting Started

Although JNWSpringAnimation is a subclass of CAKeyframeAnimation, it should be treated as if it were a subclass of CABasicAnimation.

To get started, copy the four source files into your project.

The animation can be created by using the dedicated initializer, +animationWithKeyPath:. Alternatively, the animation can be created using +animation and by setting the key path afterwards. The full list of currently-compatible animatable properties is available in the header.

JNWSpringAnimation *animation = [JNWSpringAnimation animationWithKeyPath:@"position.x"];

Next, the fromValue and toValue properties must be set for the interpolated values to be calculated correctly.

animation.toValue = @(toX);
animation.fromValue = @(currentX);

Finally, the values for the spring constants can optionally be changed. Currently, stiffness, damping, and mass are available for modification.

animation.mass = 30; // this will move extremely slowly
// and so on

The animation itself can be applied like any other subclass of CAAnimation, namely -addAnimation:forKey: on any CALayer.

What's this for?

This was created in my desire to have an open-source version of the (currently private) CASpringAnimation which was discovered in iOS 6.

Spring animations, when used appropriately, can really enhance the way your app feels to the user by connecting in physical simulations with an app's interface. And besides, who doesn't love messing around with springs?

What's left to do?

I created this as a weekend project, so the implementation is still somewhat unfinished. Compared to CASpringAnimation, the velocity property is still unimplemented. Pull requests are welcome.

License

JNWSpringAnimation is licensed under the MIT license. See LICENSE.md.

Get In Touch

You can follow me on Twitter as @willing, email me at the email listed on my GitHub profile, or read my blog at jwilling.com.

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.