使用CABasicAnimation的UIPercentDrivenInteractiveTransition [英] UIPercentDrivenInteractiveTransition With CABasicAnimation

查看:116
本文介绍了使用CABasicAnimation的UIPercentDrivenInteractiveTransition的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用手势驱动的UIPercentDrivenInteractiveTransition和CABasicAnimation(或任何其他CAAnimation)时,在finishInteractiveTransition上,动画会跳转到最终位置,而不是像使用UIView块动画时那样平滑地制作动画。我试图弄清楚如何在使用CAAnimation时finishInteractiveTransition平滑动画。

When using gesture driven UIPercentDrivenInteractiveTransition with CABasicAnimation (or any other CAAnimation), upon finishInteractiveTransition, animation jumps to final position, rather then animating smoothly as is the case when using UIView block animation. I am trying to figure out how to animate smoothly upon finishInteractiveTransition to end when using CAAnimation.

我现在花了一整天时间。似乎没有任何关于将CAAnimation与自定义VC转换一起使用的提及,每个人都引用基于UIView块的动画。

I have now spent whole day on it. There seems to be no mention anywhere about using CAAnimation with custom VC transitions, everyone refers to UIView block based animation.

我创建了一个演示问题的小样本项目。

I have create a small sample project that demonstrates problem.

https://github.com/stringcode86/UIPercentDrivenInteractiveTransitionWithCABasicAnimation

感谢任何花时间看它的人。我很感激。

Thank you to anyone who spends time looking at it. I do appreciate it.

推荐答案

解决方案

事实证明解决方案是操纵图层的开始时间。我将尝试在下面更深入地解释解决方案。有两种解决方案,一种是使用 UIPercentDrivenTransition 子类或实现 UIViewControllerInteractiveTransitioning 协议。自定义UIViewControllerInteractiveTransitioning位于主分支上,UIPercentDrivenTransition实现位于UIPercentDrivenTransitionImplementation分支上。

As it turns out solution is to manipulate layers begin time. I am going to try to explain the solution in bit more depth below. There are two solution one using UIPercentDrivenTransition subclass or implementing UIViewControllerInteractiveTransitioning protocol. Custom UIViewControllerInteractiveTransitioning is on the master branch and UIPercentDrivenTransition implementation is on UIPercentDrivenTransitionImplementation branch.

https://github.com/stringcode86/UIPercentDrivenInteractiveTransitionWithCABasicAnimation

EXPLANATION

EXPLANATION

UIPercentDrivenTransition在animateTransition中使用动画:实现 updateInteractiveTransition:。我猜他们只是从 startInteractiveTransition:调用 animateTransition:,然后将图层(可能是容器视图图层)的速度设置为0.0并操纵其 timeOffSet 。这允许他们自动前后移动过渡。这适用于你的UIView动画。 CAAnimations的问题是他们的 begingTime timeOffSet speed 属性由于某种原因未正确设置。如果将它们设置为合理值,则可以在containerView中来回移动所有动画内容。我创建了 SCPercentDrivenTransition 女巫替代 UIPercentDrivenTransition 。您只需覆盖animateTransition:并从手势识别器操作调用中调用handleGesture:

UIPercentDrivenTransition uses animations in animateTransition: to implement updateInteractiveTransition: . I am guessing they simply call animateTransition: from startInteractiveTransition: and then set layer (perhaps containers view layer) speed to 0.0 and manipulate its timeOffSet. This allow them to automatically move your transition back and forward. This does it for your UIView animations. Problem with CAAnimations is their begingTime, timeOffSet, speed properties are not set correctly for some reason. If you set those to sensible values, you are able to move all animated content in containerView back and forth. I have created SCPercentDrivenTransition witch is alternative to UIPercentDrivenTransition. You only need to override animateTransition: and call handleGesture: from your gesture recognisers action calls.

这篇关于使用CABasicAnimation的UIPercentDrivenInteractiveTransition的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆