取消UIView动画?

取消UIView动画?

是否可以在UIView动画进行过程中取消动画?或者我是否必须降至CA级别?


即我已经完成了这样的事情(也可能设置一个结束动画动作):


[UIView beginAnimations:nil context:NULL];

[UIView setAnimationDuration:duration];

[UIView setAnimationCurve: UIViewAnimationCurveLinear];

// other animation properties


// set view properties


[UIView commitAnimations];

但是在动画完成之前我得到动画结束事件,我想取消它(剪短它)。这可能吗?谷歌搜索周围发现一些人问同样的问题没有答案 - 一两个人推测它不能完成。


九州编程
浏览 1448回答 3
3回答

红糖糍粑

我这样做的方法是为你的终点创建一个新的动画。设置一个非常短的持续时间,并确保使用该+setAnimationBeginsFromCurrentState:方法从当前状态开始。将其设置为YES时,将缩短当前动画。看起来像这样:[UIView beginAnimations:nil context:NULL];[UIView setAnimationBeginsFromCurrentState:YES];[UIView setAnimationDuration:0.1];[UIView setAnimationCurve: UIViewAnimationCurveLinear];// other animation properties// set view properties[UIView commitAnimations];

临摹微笑

使用:#import <QuartzCore/QuartzCore.h>.......[myView.layer removeAllAnimations];

jeck猫

停止最简单的方法都在特定视图动画,立刻,是这样的:将项目链接到QuartzCore.framework。在代码的开头:#import <QuartzCore/QuartzCore.h>现在,当你想停止视频中的所有动画时,请说:[CATransaction begin];[theView.layer removeAllAnimations];[CATransaction commit];中间线本身可以工作,但是在runloop完成之前有一段延迟(“重绘时刻”)。要防止该延迟,请将命令包装在显式事务块中,如图所示。这项工作在当前的runloop中没有对该层执行任何其他更改。
打开App,查看更多内容
随时随地看视频慕课网APP