是否可以在UIView动画进行过程中取消动画?或者我是否必须降至CA级别?
即我已经完成了这样的事情(也可能设置一个结束动画动作):
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
// other animation properties
// set view properties
[UIView commitAnimations];
Run Code Online (Sandbox Code Playgroud)
但是在动画完成之前我得到动画结束事件,我想取消它(剪短它).这可能吗?谷歌搜索周围发现一些人问同样的问题没有答案 - 一两个人推测它不能完成.
我正在使用[UIView animateWithDuration ...]来显示我的应用程序的每个页面的文本.每个页面都有自己的文本.我正在刷卡以在页面之间导航.我正在使用1秒的溶解效果,在显示页面后让文本淡入.
问题在于:如果我在1秒内(在此期间文本渐渐消失)中滑动,则当下一页出现并且2个文本将重叠(前一个和当前)时,动画将完成.
我想要实现的解决方案是,如果我碰巧在它发生时滑动,就会中断动画.我无法实现它.[self.view.layer removeAllAnimations]; 不适合我.
这是我的动画代码:
- (void) replaceContent: (UITextView *) theCurrentContent withContent: (UITextView *) theReplacementContent {
theReplacementContent.alpha = 0.0;
[self.view addSubview: theReplacementContent];
theReplacementContent.alpha = 0.0;
[UITextView animateWithDuration: 1.0
delay: 0.0
options: UIViewAnimationOptionTransitionCrossDissolve
animations: ^{
theCurrentContent.alpha = 0.0;
theReplacementContent.alpha = 1.0;
}
completion: ^(BOOL finished){
[theCurrentContent removeFromSuperview];
self.currentContent = theReplacementContent;
[self.view bringSubviewToFront:theReplacementContent];
}];
}
Run Code Online (Sandbox Code Playgroud)
你们知道如何使这项工作?你知道其他任何解决这个问题的方法吗?