我有一个动画 block ,可以将 UIImageView
从屏幕顶部移动到底部。如果用户在动画期间的任何时候点击屏幕,我希望 UIImageView
停在它所在的位置。
目前,我有
[UIView animateWithDuration:3 delay:0 options:UIViewAnimationOptionCurveLinear animations:^(void){
[self.myImage setCenter:CGPointMake(self.view.frame.size.width/2,self.view.frame.size.height-20)];
}];
[self.view.layer removeAllAnimations];
但是 removeAllAnimations
不会阻止我的 UIImageView 动画...
最佳答案
开始一个持续时间为 0.0 的新动画将取消之前的动画并开始新的动画。那还不如什么也不做,让你的 UIImageView
保持在用户停止它的位置:
[UIView animateWithDuration:0.0
delay:0.0
options:UIViewAnimationOptionBeginFromCurrentState
animations:^{redView.frame = ((CALayer *)redView.layer.presentationLayer).frame;}
completion:^(BOOL finished){
[CATransaction begin];
[redView.layer removeAllAnimations];
[CATransaction commit];
}];
BeginFromCurrent 状态让您可以在任何地方拍摄图像。
关于ios - 在不删除 UIView 的情况下取消 UIAnimation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26704821/