IOS: springWithDamping as animation for KeyFrame animation

I had the following custom transition using UIView.animateWithDuration(...usingSpringWithDamping:...) which worked fine.

 UIView.animateWithDuration(self.transitionDuration(transitionContext), delay: 0.0, usingSpringWithDamping: 0.8, initialSpringVelocity: 1.0, options: nil, animations: {() in // ... }, completion: {(Bool) in // ... }) 

But then I had to expand my custom transition using UIViewControllerInteractiveTransitioning to have an interactive transition where the user can view the modal view again.

Therefore, I need keyframes for the animation so that UIPercentDrivenInteractiveTransition works correctly.

So I changed the animation function to use UIView.animateWithKeyframes...

 UIView.animateKeyframesWithDuration(self.transitionDuration(transitionContext), delay: 0.0, options: UIViewKeyframeAnimationOptions.CalculationModeCubic, animations: {() in // ... }, completion: {(Bool) in // ... }) 

My problem now: I lost the spring animation.

I checked several links, one of the most promising was:

... but with the .addKeyframes... method .addKeyframes... I cannot specify the required termination block.

Any suggestions?: -/

+6
source share
1 answer

Try the following:

 UIView.animateKeyframesWithDuration(self.transitionDuration(transitionContext), delay: 0.0, options: UIViewKeyframeAnimationOptions.CalculationModeCubic, animations: {() in UIView.addKeyframeWithRelativeStartTime(0.0, relativeDuration:0.5, animations: {() in // first animation }) UIView.addKeyframeWithRelativeStartTime(0.5, relativeDuration:0.5, animations: {() in // spring animation }) }, completion: {(Bool) in // cleaning }) 
0
source

Source: https://habr.com/ru/post/986169/


All Articles