Code Monkey home page Code Monkey logo

Comments (14)

kimon avatar kimon commented on September 17, 2024

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.

callmeed avatar callmeed commented on September 17, 2024

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.

grp avatar grp commented on September 17, 2024

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.

limboy avatar limboy commented on September 17, 2024

@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.

callmeed avatar callmeed commented on September 17, 2024

@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.

chady avatar chady commented on September 17, 2024

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.

aleclarson avatar aleclarson commented on September 17, 2024

I would appreciate something like what's been described here!

from pop.

grp avatar grp commented on September 17, 2024

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.

grp avatar grp commented on September 17, 2024

@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.

limboy avatar limboy commented on September 17, 2024

@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.

pronebird avatar pronebird commented on September 17, 2024

Anyone managed to do the reverse math for velocity/deceleration based on target position? I have a hard time with formulas here :/

from pop.

hfossli avatar hfossli commented on September 17, 2024

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.

pronebird avatar pronebird commented on September 17, 2024

@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.

hfossli avatar hfossli commented on September 17, 2024

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)

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.