Comments (14)
POPDecayAnimation takes a fromPosition and velocity as initial values. The destination value is derived based on those inputs. Check out the README for an example.
from pop.
Ok, understood ... thanks for the clarification (and the project).
For decaying to a specific value, it looks like I'll have to do math :/
from pop.
Yeah, if you do the math you could adjust the decay constant to land at a specific place.
If you end up doing that (and want to contribute that function back), it's an API worth supporting. Could make the animation use the toValue
if set, and fall back to the decay constant if not.
from pop.
@grp it seems not so convenient in use, i.e slide a view from bottom to top.
PS: what is the formula to calculate the velocity / deceleration based on toValue?
from pop.
@lzyy it looks like the current formula is in POPDecayAnimationInternal.h ... so, you could probably reverse it to do it based on toValue
from pop.
This could probably be usefuly to provide an edge. I want to decay animation on flick, but I want it to bounce on some specified edge. I can't see a way of doing that right now. Maybe the toValue could be used for that.
from pop.
I would appreciate something like what's been described here!
from pop.
If you're looking to bounce at an edge, a toValue
wouldn't be very useful βΒ it would just change where the decay ends up. Instead, I'd suggest swapping out the POPDecayAnimation
for a POPSpringAnimation
when you see the decay has passed the edge.
One way to check if you've passed an edge is in the animation delegate method pop_animationDidApply:
. When the decay animation applies, you can check if it's past the edge. If it is, then start the spring animation & stop the decay. (You might copy the current velocity
from the POPDecayAnimation
to the POPSpringAnimation
to make sure it feels smooth.)
from pop.
@lzyy I think you'd likely need to derive that formula from the existing POPDecayAnimation
formulas. If you write them out as equations, I don't think it'll be that bad.
from pop.
@grp "swapping out the POPDecayAnimation
for a POPSpringAnimation
" is really inspiring, thanks.
yes, the formula is in POPDecayAnimationInternal.h
, if kCAMediaTimingFunctionEaseOut
is not sufficient, will use that.
from pop.
Anyone managed to do the reverse math for velocity/deceleration based on target position? I have a hard time with formulas here :/
from pop.
If POPDecayAnimation is just following standard deceleration rules this method should give you the acceleration/deceleration for the desired distance and velocity.
+ (CGFloat)decelerationForDistance:(CGFloat)distance withVelocity:(CGFloat)velocity
{
if(distance == 0.0)
{
return 0.0;
}
if(velocity == 0.0)
{
return 0.0;
}
double acceleration = ((velocity * velocity)) / (distance * 2.0);
double deceleration = 1.0 / fabs(acceleration);
return MIN(0.9999999, MAX(0.0, deceleration));
}
I haven't tested it with POP, but try and let us know
from pop.
@hfossli ah now I see, I had some issues adapting calculated acceleration to deceleration value used by POP.
I put together a sample app here based on your function:
https://gist.github.com/pronebird/f62330a395712c41feaa
So basically I want to move my from point A (0, 0) to point B (100, 0) with initial velocity = (50, 0).
So we have:
distance = 100 units
acceleration = 12.5
deceleration factor = 0.999
POP calculated coordinate is: 44.956
decay = <POPDecayAnimation:0x79d03ed0; from = (0.000, 0.000); to = (44.956, 0.000); velocity = (50.000, 0.000); duration = 2.301463; deceleration = 0.999000>
from pop.
Well, my attempt was garbage. Seems like the formulas are quite more complicated looking at the POPDecayAnimationInternal.h
. I guess what's complicating this is the rest/threshold-concept.
from pop.
Related Issues (20)
- paper link does not exist
- Couldnt be able to integrate this with Swift 3.0 project by following the same commands. HOT 1
- No such file or directory error while building the workspace
- Errors should be thrown when animation parameters don't match animation parameters
- In memory of the Facebook Paper HOT 1
- Why not kPOPLayerRotationZ this enumeration? I want to rotate the animation around the Z axis. HOT 2
- Cannot works with Snapkit?
- Do you have the scenekit+pop demo?
- iostream file not found - Xcode 9.3.1 - Swift 4 HOT 3
- How to get the progress of the animation
- _POPPropertyAnimationState isPaused reset the progress
- Installation
- CocoaPods update HOT 5
- If toValue equals the target's current value then completionBlock will fire immediately HOT 1
- Carthage issue HOT 1
- problem with same animation HOT 1
- i feel confused ,what the function work for β [self _scheduleProcessPendingList]β
- POPSpringAnimation removedOnCompletion not working
- Spring animation not working anymore following iOS 13 update HOT 5
- Swift Package Manager Support
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
π Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google β€οΈ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pop.