gpt4 book ai didi

ios - 当动画添加到 subview 时立即调用 CATransaction 完成 block

转载 作者:行者123 更新时间:2023-11-29 05:56:50 27 4
gpt4 key购买 nike

我试图在新添加的 UIImageView 作为 subview 上启动动画,但在这种情况下似乎会立即调用完成 block ,即使动画是在 CATransaction.setCompletionBlock 之后添加的

addSubview(imageView)

CATransaction.begin()

let posAnimation = positionAnimation(startPoint: startPoint, endPoint: endPoint, beginTime: beginTime, duration: duration)
let alpAnimation = alphaAnimation(beginTime: beginTime, duration: duration)

CATransaction.setCompletionBlock{ [weak self] in
print("deleting view")
//imageView.removeFromSuperview()
}

imageView.layer.add(posAnimation, forKey: nil)
imageView.layer.add(alpAnimation, forKey: nil)

CATransaction.commit()

动画:

private func positionAnimation(startPoint: CGPoint, endPoint:CGPoint, beginTime: CFTimeInterval, duration: CFTimeInterval) -> CAKeyframeAnimation {
let positionAnimation = CAKeyframeAnimation(keyPath: "position")

positionAnimation.path = customPath(middlePoint: startPoint, endPoint: endPoint).cgPath
positionAnimation.isRemovedOnCompletion = false
positionAnimation.duration = duration
positionAnimation.beginTime = beginTime
positionAnimation.fillMode = CAMediaTimingFillMode.forwards
return positionAnimation
}

private func alphaAnimation(beginTime: CFTimeInterval, duration: CFTimeInterval) -> CAKeyframeAnimation {
let alphaAnimation = CAKeyframeAnimation(keyPath: "opacity")
alphaAnimation.isRemovedOnCompletion = false
alphaAnimation.fillMode = CAMediaTimingFillMode.forwards
alphaAnimation.values = [1.0, 1.0, 0.0]
alphaAnimation.keyTimes = [0.0,0.5,1.0]
alphaAnimation.duration = duration
alphaAnimation.beginTime = beginTime
return alphaAnimation
}

知道为什么它不起作用吗?

最佳答案

显然,动画不在渲染树上。即 View 没有 superView。或其 superView 的某个地方没有 superView。您可能需要检查 View 实现函数是否已添加到 windowview 某处。

关于ios - 当动画添加到 subview 时立即调用 CATransaction 完成 block ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55072194/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com