gpt4 book ai didi

ios - 我们是否总是需要在持久属性中保留动画?

转载 作者:行者123 更新时间:2023-12-01 19:30:17 24 4
gpt4 key购买 nike

目前我正在阅读 Matt Neuburg 的非常有趣的书。但我坚持这一刻:

In the simplest case, you’ll just launch the animation and stand back,as I demonstrated earlier:

let anim = UIViewPropertyAnimator(duration: 1, curve: .linear) {
self.v.backgroundColor = .red
}
anim.startAnimation()

In that code, the UIViewPropertyAnimator object anim is instantiated as a local variable, and we are notretaining it in a persistent property; yet the animation works becausethe animation server retains it.


当我们以上述方式使用动画时,是否需要在持久属性中保留动画?如果我们不将动画保留在持久属性中,为什么动画(在其他情况下似乎)不应该工作?我想我不明白还有谁读过这本书?

最佳答案

Matt 的观点是,您不需要保留对它的引用来完成动画。他并不是说您不能保留引用资料,只是说您不必保留。
你问:

Did we ever need to retaining an animation in a persistent property when we using it in [aforementioned] way?


不,您无需“保留”它即可继续制作动画。
您可能会问为什么要保留引用:如果您想在动画开始后暂停或停止它、擦洗它或其他什么,您可能会这样做。
底线,如果您出于其他原因需要引用,很好,请保留对它的引用。否则,只需将其设为局部变量并启动它即可。

Why animation (it seems in other cases) should not work if we do not retain it in a persistent property?


他不是这么说的。他说的恰恰相反,即你不必为动画继续保持强烈的引用。如果您出于其他原因需要它,请保留引用,但不仅仅是为了确保动画继续播放。

关于ios - 我们是否总是需要在持久属性中保留动画?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63258012/

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