我已经搜索了很多苹果的参考资料,但仍然无法解决我的问题.

我拥有的:

  1. 连接有2个UIImageView和2个UIButton的屏幕
  2. 2 kinds of animation:
    1. 放大和缩小每个图像,一个接一个,每viewDidLoad个图像中只有一个
    2. 当按下一个按钮(一个自定义按钮隐藏在每UIImageView个按钮的"内部")时,它会触发相应UIImageView的动画–只有一个,而不是两个–同时放大,然后缩小.
    3. 当我为IOS4+写作时,我被告知要使用基于挡路的动画!

我需要的是:

如何取消正在运行的动画?我已经设法取消了,除了最后一次.:/

以下是我的代码片段:

[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");
                                      }];
            }];
        }];
    }];

不知何故,smallLetterUIImageView不能正常工作,因为当按下(通过按钮)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
     ];
}

问题依然存在……:/不知道如何中断动画链中字母的最后一个动画

推荐答案

您可以通过调用以下命令来停止视图上的所有动画:

[view.layer removeAllAnimations];

(您需要导入QuartzCore框架来调用view.layer上的方法).

如果要停止特定动画(而不是所有动画),最好的方法是显式使用CAAnimations,而不是UIView动画辅助对象方法,这样您将拥有更精细的控制,并且可以按名称显式停止动画.

可在此处找到Apple Core动画文档:

https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CoreAnimation_guide/CreatingBasicAnimations/CreatingBasicAnimations.html

Ios相关问答推荐

UIBezierPath包含:方法不检测到厚度大于1像素的线上的touch

DriverKit驱动程序中可能存在IOBufferMemoyDescriptor泄漏

创建带有Flutter 翼的会所头像

当重新呈现UI时,嵌套的 struct 值如何与@Observable一起工作?

如何删除NavigationView中的默认透明标头?

mapView swift 导致警告有网格错误

保存和读取登录到 keys 串不工作 IOS swift

更改初始控制器无效

圆角矩形路径上的蛇形动画

如何在Swift/Combine中从timer.publish属性传递两个参数到任意方法

ITMS-90725 无用的错误信息,因为它自相矛盾,苹果上传

Swift Combine 防止初始值触发接收器并同时防止重复?

我需要二进制文件来进行 App Store 应用程序传输吗?

为 ColorPicker 创建一个名为 Color 的计算变量的绑定

为什么 Safari 在使用 iOS 6 设备进行远程调试时显示No Inspectable Applications?

UIButton 事件.有什么不同?

在滚动视图中使用动态大小的控制器调整容器视图的大小

AFNetworking 2.0 向 GET 请求添加标头

iTunes Connect 中的无限制 Web 访问是什么意思

检测应用程序何时进入我的视图背景的最佳方法是什么?