我已经搜索了大量的SO资料和苹果的参考资料,但仍然无法解决我的问题。
我所拥有的:
UIImageView
和2个UIButton
连接的屏幕viewDidLoad
UIImageView
内部的自定义按钮)它会触发相应的<UIImageView
>D12的动画(也可以放大,然后缩小)。
我需要的是:
如何取消正在运行的动画?我已经设法取消了,除了最后一次...:/
下面是我的代码片段:
[UIImageView animateWithDuration:2.0
delay:0.1
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
isAnimating = YES;
self.bigLetter.transform = CGAffineTransformScale(self.bigLetter.transform, 2.0, 2.0);
} completion:^(BOOL finished){
if(! finished) return;
[UIImageView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.bigLetter.transform = CGAffineTransformScale(self.bigLetter.transform, 0.5, 0.5);
} completion:^(BOOL finished){
if(! finished) return;
[UIImageView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.smallLetter.transform = CGAffineTransformScale(self.smallLetter.transform, 2.0, 2.0);
} completion:^(BOOL finished){
if(! finished) return;
[UIImageView animateWithDuration:2.0
delay:0.0
options:UIViewAnimationOptionAllowUserInteraction
animations:^{
self.smallLetter.transform = CGAffineTransformScale(self.smallLetter.transform, 0.5, 0.5);
}
completion:^(BOOL finished){
if (!finished) return;
//block letter buttons
[self.bigLetterButton setUserInteractionEnabled:YES];
[self.smallLetterButton setUserInteractionEnabled:YES];
//NSLog(@"vieDidLoad animations finished");
}];
}];
}];
}];
不知何故,smallLetter
UIImageView
不能正常工作,因为当按下(通过按钮) bigLetter
时会正确地取消动画...
EDIT:我已经使用了这个解决方案,但是在缩小smallLetter
UIImageView
时仍然有问题--根本没有取消...solution
EDIT2:我在next/prev方法的开头添加了以下内容:
- (void)stopAnimation:(UIImageView*)source {
[UIView animateWithDuration:0.01
delay:0.0
options:(UIViewAnimationOptionBeginFromCurrentState | UIViewAnimationOptionAllowUserInteraction)
animations:^ {
source.transform = CGAffineTransformIdentity;
}
completion:NULL
];
}
问题仍然存在..。:/不知道如何中断动画链中字母的最后一个动画
发布于 2012-03-13 07:57:04
您可以通过调用以下命令停止视图上的所有动画:
[view.layer removeAllAnimations];
(您需要导入QuartzCore框架才能在view.layer上调用方法)。
如果要停止特定动画,而不是所有动画,最好的方法是显式使用CAAnimations,而不是UIView动画辅助方法,这样您将拥有更精细的控制,并且可以按名称显式停止动画。
可以在以下位置找到Apple Core动画文档:
发布于 2016-12-31 04:20:23
对于iOS 10,使用UIViewPropertyAnimator设置动画。它提供了启动、停止和暂停UIView动画的方法。
let animator = UIViewPropertyAnimator(duration: 2.0, curve: .easeOut){
self.view.alpha = 0.0
}
// Call this to start animation.
animator.startAnimation()
// Call this to stop animation.
animator.stopAnimation(true)
发布于 2014-10-20 07:35:15
我会补充尼克的答案,使removeAllAnimations平滑下一个想法是非常方便的。
[view.layer removeAllAnimations];
[UIView transitionWithView:self.redView
duration:1.0f options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
[view.layer displayIfNeeded];
} completion:nil];
https://stackoverflow.com/questions/9569943
复制相似问题