ios - 在不删除 UIView 的情况下取消 UIAnimation

标签 ios objective-c

我有一个动画 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/

相关文章:

ios - 向 UISearchController 添加过滤器按钮

ios - 为什么 Swift 中的方法可以有没有类型的参数?

objective-c - 如何在 Objective-C 中保持输出流打开?

ios - 如何从 Amazon S3 下载 - iOS

objective-c - 当 tabBarController/navController 在同一应用程序中时推送到详细 View 时出现问题

ios - Delphi XE6 firemonkey组件在运行时添加时对齐问题

android - 同一语言的两个版本的应用程序本地化

ios - 更改 UIViewController 后 NSNotificationCenter 崩溃

javascript - 从 javascript/angularjs 背景学习 Objective-C/swift

objective-c - Mac OS X 代理上同步请求的随机错误