iOS层动画-说明 [英] iOS layer animation - explanation

查看:74
本文介绍了iOS层动画-说明的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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秒后按预期方式工作。

My question is: how is it possible that before I am adding the animation, I first put the layer at the end position, but when the app goes up, I don't see it there before the animation starts? Instead, the animation works after 3.4 seconds as expected.

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

I mean, how iOS knows that first it needs to run the animation and only then put the layer to it's final position?

推荐答案

这是因为存在 presentationLayer modelLayer 以便动画显示并修改 presentationLayer ,所以 presentationLayer 就像是鬼

This is because there is a presentationLayer and a modelLayer so animation show and modify presentationLayer, so presentationLayer is like a ghost.


您可能知道UIView实例以及支持图层的NSView修改了其图层,以将渲染委派给功能强大的Core
动画框架。但是,重要的是要了解
动画在添加到图层后,请勿直接修改其属性

而是,Core Animation维护两个并行的层层次结构:模型层树和表示层树。
中的图层反映了图层的众所周知状态,而后者中的图层仅近似
动画的运行中值。
考虑向视图中添加淡出动画。如果您在动画制作过程中的任何时候检查图层的不透明度值,则
最有可能不会获得与屏幕上所对应的不透明度。
相反,您需要检查表示层以获得正确的
结果。
虽然您可能无法直接设置表示层的属性,但使用其当前值来创建新的
动画或在动画占据
的位置与图层交互可能会很有用。
通过使用-[CALayer PresentationLayer]和-[CALayer modelLayer],您可以轻松地在两层层次结构之间切换。

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 /

you can find more info here https://www.objc.io/issues/12-animations/animations-explained/

我希望这对您有帮助

这篇关于iOS层动画-说明的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆