ios - 移除 CoreGraphics 动画

标签 ios swift core-animation

如何使用 animationDidStop 删除动画?

我应用动画

let animationTwo = CABasicAnimation(keyPath: "opacity")
animationTwo.delegate = self
animationTwo.fromValue = 0.0
animationTwo.toValue = 1.0
animationTwo.duration = 1.0
animationTwo.timingFunction = CAMediaTimingFunction(name: .easeInEaseOut)
myView.layer.add(animationTwo, forKey: "fade")

然后尝试删除它

func animationDidStop(_ anim: CAAnimation, finished flag: Bool) {
    if anim == myView.layer.animation(forKey: "fade") {
        myView.layer.removeAnimation(forKey: "fade")
    }
}

但是 anim == myView.layer.animation(forKey: "fade") 永远不会解析为 true。

动画完成后如何删除?

最佳答案

CAAnimation 有一个名为 isRemovedOnCompletion 的属性,默认为 true

这意味着您的动画在完成后将从渲染树中移除。我想这就是为什么 anim == myView.layer.animation(forKey: "fade") 没有解析为 true 因为它已经被删除了。

关于ios - 移除 CoreGraphics 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57744485/

相关文章:

ios - 如何在 UITableViewController 的静态单元格中添加 UIView?

ios - Cordova 3.4 iOS 应用程序在 iOS 8.1.1 上崩溃

iphone - 基本关键帧动画(旋转)

ios - 取消一个 UIView 动画?

ios - ECSlidingViewController 与 UIScrollView

ios - 无法从 firebase 中删除图像?

swift - 为什么不能使用 T 作为前缀运算符的返回类型?

objective-c - 如何在 Swift 或 Objective-C 中获取 JSON 数据结构的人类可读映射?

ios - 将自定义输入 View 设置为全局所有文本字段的最简单方法

ios - UIView animateKeyFrames 未按预期工作