Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
457 views
in Technique[技术] by (71.8m points)

ios - UIPercentDrivenInteractiveTransition With CABasicAnimation

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.

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

SOLUTION

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

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...