是否可以在UIView动画正在进行时取消它?还是我必须降到CA级别?

i、 e.我做过类似的事情(可能还会设置一个结束动画动作):

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:duration];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
// other animation properties

// set view properties

[UIView commitAnimations];

但是在动画完成并且我得到动画结束事件之前,我想取消它(缩短它).这个是可能的吗?在谷歌上搜索一下,发现有几个人问了同样的问题,但没有答案-还有一两个人猜测这是不可能的.

推荐答案

我的方法是创建一个指向终点的新动画.设置非常短的持续时间,并确保使用+setAnimationBeginsFromCurrentState:方法从当前状态开始.当您将其设置为YES时,当前动画将被缩短.如下所示:

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.1];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
// other animation properties

// set view properties

[UIView commitAnimations];

Ios相关问答推荐

2024 Beacon应用程序- startMonitoring(适用于:地区)或

Swift addtarget方法的默认参数不生效

ITMS—91053:Flutter Project中缺少API声明

删除领域中的cartItem时出现问题

为什么下面的代码没有在主线程上运行?

拖动手势导致 sim 崩溃 Swift UI

iOS设备网页自动化中,在向字段发送文本后未启用按钮

在Xcode 15中为具有@Binding的视图创建SwiftUI #预览的方法

Flutter iOS 构建失败:DVTCoreDeviceEnabledState_Disabled

使用 JSONDecoder 解码的对象的打印输出有问题

使用 Foundation 解压缩文件

NSOperation 有延迟 - 它是异步的还是同步的?

集成 IDNow SDK 时未找到 Xcode FLAnimatedImage.h 文件问题

包装在 AnyView 中时 UIViewControllerRepresentable 无法正常工作

如何在 iPhone 中为透明的 PNG 图像着色?

interfaceOrientation在 iOS 8 中已弃用,如何更改此方法 Objective C

@IBDesignable 崩溃代理

如何以编程方式切换 UISegmentedControl?

如何在 UILabel 中找到文本子字符串的 CGRect?

判断从 JSON 字符串返回的 Objective-C 中的空值