jwilling / jnwspringanimation Goto Github PK
View Code? Open in Web Editor NEWSpring physics for Core Animation.
License: MIT License
Spring physics for Core Animation.
License: MIT License
CGRectValue CGSizeValue CGPointValue are defined in UIKit, CGRect CGSize CGPoint ..are defined in CG, UIKit
should be imported here.
I was doing some research on spring-based animations and found this library while in the process of building a new feature for @NimbusKit. Your implementation is a solid step towards providing spring-based animations, but initial velocity support is key to enabling natural gesture-based animations we're starting to see in more apps and it sadly hasn't been implemented here yet.
This paper by David Morin has a wonderful section on using initial conditions with harmonic oscillators (section 1.1.7). From there we can see that the addition of (velocity / freq) * sin(freq * t)
to the harmonic oscillation allows us to incorporate initial velocity into the oscillation.
Sidenote: in practice I found that if the delta (
A
) is negative then you have to flip the sign of the velocity (v
) in order for it not to behave erratically.
I made a grapher file so that I could play with the curves a bit easier. Screenshot follows (can't upload the grapher file to Github sadly). The shorter curve of the two is a damped harmonic oscillation without velocity taken into account (effectively v = 0
). The taller curve is a damped harmonic oscillation with an initial velocity of 20 (intuitively: the sign affects which direction we overshoot in, the amplitude by how much).
Velocity pointing toward the delta.
Velocity pointing away from the delta.
Example of an iOS 7-style spring animation being thrown toward the destination.
Example of an initial-velocity spring animation being thrown away from the destination.
This is primarily an FYI right now, as I'm not going to use your library in the feature I'm building. The approach I plan to go with will likely not be a subclass of CAAnimation
at all, opting instead for a more generalized approach to building key frames for a spring-with-initial-velocity-based tween. The lack of correct transform tweening in this library is problematic, but properly implementing transform tweening requires non-trivial quaternion work, and CAAnimation likely already does that underneath the hood (linked code is not official), so I plan to just let CAKeyFrameAnimation
do its magic rather than try to rebuild that code.
Thanks for providing a test bed with which I could more quickly play with this! Your code definitely helped point me in the right direction as far as researching papers and playing with graphs.
Cheers!
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.