Skip to content
This repository has been archived by the owner on Mar 3, 2020. It is now read-only.

I want to know POPSpringAnimation's duration time. #134

Closed
WilliamZang opened this issue Jul 21, 2014 · 8 comments
Closed

I want to know POPSpringAnimation's duration time. #134

WilliamZang opened this issue Jul 21, 2014 · 8 comments

Comments

@WilliamZang
Copy link

Can I get how long the POPSpringAnimation will last?
How can I specify a duration time?

@grp
Copy link
Contributor

grp commented Jul 21, 2014

Spring animations are physics simulations, so there isn't a real concept of a duration. For example, you can change the toValue of the spring animation while it's active, which could redirect the animation to a new place and completely change the duration.

What do you need the duration for? We might be able to suggest something else you could use.

@WilliamZang
Copy link
Author

@grp I want to implement viewcontroller transition, so it need a duration time for method - (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext

@grp
Copy link
Contributor

grp commented Jul 22, 2014

Ah. I'm not sure how those work with Pop, since they're fairly closely tied to the UIView animation system. Perhaps try returning 0 and doing the animation with Pop yourself?

@WilliamZang
Copy link
Author

I think it may work with pop, the only thing is duration time.

@grp
Copy link
Contributor

grp commented Jul 22, 2014

Pop spring animations don't conceptually have a duration, so I'm not sure you can directly integrate them with this system. Have you tried estimating a time that makes sense for your transition?

@WilliamZang
Copy link
Author

Yes, estimating a time is OK. All right, I'll let fade out animation have a specify duration time, but let fade in animation use estimating time.

@toulouse
Copy link
Contributor

toulouse commented Aug 7, 2014

To clarify for anyone else interested in why - the way spring animations work is that they oscillate, damped according to their configuration options, until they are within some threshold and are then considered to have "converged".

In order to calculate a time, you could theoretically try to run the physics simulation's mathematical calculation yourself until it converges. Using that, you would determine how many ticks of the animator it would take to converge. Pop's animator is powered by CADisplayLink, so a tick would be roughly once per frame, or 16.67ms.

Unfortunately, this would still, at best, be an estimate, as any frame drops could cause this calculation to fail in the face of a time deadline that wasn't affected by frame drops. Additionally, as the developer, you would need to be absolutely sure the spring animation's parameters did not change during this time-dependent operation, as that too would invalidate the calculation.

tl;dr: Springs can't tell you ahead of time when they will converge, only that they have converged. Unless you can accurately predict frame drops (or don't have any at all), you can't accurately predict the exact length of the spring animation, either. In situations which require a hard time limit, estimation is a good approach.

@WilliamZang
Copy link
Author

OK,I see it.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants