gpt4 book ai didi

iOS图层动画-解释

转载 作者:搜寻专家 更新时间:2023-11-01 06:19:04 26 4
gpt4 key购买 nike

let flyRight = CABasicAnimation(keyPath: "position.x")
flyRight.toValue = view.bounds.size.width/2
flyRight.duration = 0.5
flyRight.fromValue = -view.bounds.size.width/2
flyRight.fillMode = kCAFillModeBoth
flyRight.beginTime = CACurrentMediaTime() + 3.4
password.layer.position.x = view.bounds.size.width/2
password.layer.addAnimation(flyRight, forKey: nil)

我的问题是:怎么可能在我添加动画之前,我首先将图层放在结束位置,但是当应用程序上升时,我在动画开始之前看不到它?相反,动画会按预期在 3.4 秒后运行。

我的意思是,iOS 如何知道它首先需要运行动画,然后才将图层放到它的最终位置?

最佳答案

这是因为有一个presentationLayer和一个modelLayer所以动画展示和修改presentationLayer,所以presentationLayer就像一个幽灵。

You probably know that UIView instances, as well as layer-backed NSViews, modify their layer to delegate rendering to the powerful Core Animation framework. However, it is important to understand that animations, when added to a layer, don’t modify its properties directly. Instead, Core Animation maintains two parallel layer hierarchies: the model layer tree and the presentation layer tree. Layers in the former reflect the well-known state of the layers, wheres only layers in the latter approximate the in-flight values of animations. Consider adding a fade-out animation to a view. If you, at any point during the animation, inspect the layer’s opacity value, you most likely won’t get an opacity that corresponds to what is onscreen. Instead, you need to inspect the presentation layer to get the correct result. While you may not set properties of the presentation layer directly, it can be useful to use its current values to create new animations or to interact with layers while an animation is taking place. By using -[CALayer presentationLayer] and -[CALayer modelLayer], you can switch between the two layer hierarchies with ease.

您可以在此处找到更多信息 https://www.objc.io/issues/12-animations/animations-explained/

希望对你有帮助

关于iOS图层动画-解释,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37819903/

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