gpt4 book ai didi

ios - CABasicAnimation 动画(寻找)到整个时间轴上的时间位置

转载 作者:可可西里 更新时间:2023-11-01 06:06:12 26 4
gpt4 key购买 nike

我想知道 CoreAnimation 是否可以实现以下功能。

正如标题所说,如果您愿意,我想在整个时间轴动画上制作动画或寻找时间位置。

例如,假设我创建了一个 CABasicAnimation,它使用 EaseOut 缓动函数在 10 秒的整个时间轴上将 CALayer 的颜色从蓝色变为红色。

与其从头到尾播放该动画,我更喜欢更好的控制。

例如,我想说整个动画的 animateTo(50%)。这将导致动画从 0% 开始,并使用缓出功能动画到整个动画的 50%。所以动画将持续 5 秒,我们将处于颜色变换的中间。

在此之后我可以说,animateTo(20%)。这将导致动画从我们当前位置的 50% 开始,然后反向动画到总动画的 20%。所以我们最终会得到一个 3 秒的动画,并且我们将 20% 用于从蓝色到红色的颜色转换。

最后,我们只是在整个时间轴上对时间位置进行动画处理。我可以很容易地说 animateTo(5 秒) 而不是 animateTo(50%)。或 animateTo(2 秒) 而不是 animateTo(20%)。

我一直在阅读 CoreAnimation,看来我无法获得这种控制。有没有其他人用 CoreAnimation 试过这个?

谢谢!

最佳答案

最新的 SDK 为 UIKit 动画增加了一点。它可能适合您的需求...

根据文档:

New object-based, fully interactive and interruptible animation support that lets you retain control of your animations and link them with gesture-based interactions

Shiny 的新UIViewPropertyAnimator:

let animator = UIViewPropertyAnimator(duration: 3.0, curve: .easeInOut) {
self.myView.alpha = 0
}
animator.startAnimation()

animator.pauseAnimation()
animator.isReversed = true
animator.fractionComplete = 1.5 / CGFloat(animator.duration)

但是有一些限制:PropertyAnimator 需要针对 iOS 10(在撰写本文时仍处于测试阶段)。此外,动画仅限于 UIView Animatable Properties,它们是:

  • 框架
  • 边界
  • 居中
  • 转换
  • 测试版
  • 背景颜色
  • contentStretch

如果您寻求更多的灵 active 和功能,请查看一些开源库,例如 TRXAdvance :

import TRX

let tween = Tween(from: 0, to: 1, time:3, ease:Ease.Quad.easeOut) {
anyObject.anyProperty = $0
}
let reversed = tween.reversed()
reversed.seek(1.5)
reversed.start()

关于ios - CABasicAnimation 动画(寻找)到整个时间轴上的时间位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29372911/

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