Jump to content
Search Community

Spring animation

Beingenious test
Moderator Tag

Recommended Posts

Hello,

 

I would like to reproduce the iOS spring animations with tweenmax.

The idea is to get as close as possible to the rendering by passing a duration and a damping ratio.

 

UIView.animate(withDuration: duration,
               delay: delay,
               usingSpringWithDamping: dampingRatio,
               initialSpringVelocity: 0, options: [],
               animations: {
                layerA.frame.origin.x = 300
               },
               completion: nil)

How can I proceed?

Thank you very much for your help.

Link to comment
Share on other sites

I'm not sure I understand your question but I will mention: 

  1. There is no more TweenMax - that's the old syntax. The modern GSAP 3 has all that stuff neatly consolidated into a single "gsap" object. Much cleaner and easier. Same functionality. See: 
  2. GSAP doesn't do "springs" like that. You can use Elastic easing, create your own custom easing, or...
  3. There's an InertiaPlugin that can make literally any property naturally glide to a stop and you can even set a specific end value or a range as well as the initial velocity (or it can track the velocity for you). See https://greensock.com/docs/v3/Plugins/InertiaPlugin
  • Like 1
Link to comment
Share on other sites

Thanks Jack.

 

It's true that it's much simpler / clearer to use the new GSAP 3.

 

To answer my own question, I found a library that could help me make spring animations with GSAP.

https://github.com/tannerlinsley/springer

 

I can then convert dampingRatio and duration to normal tension and friction to use it.

https://stackoverflow.com/questions/50029666/determine-springwithdamping-and-initialspringvelocity-based-off-from-friction-an

 

Have a great day

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...