gpt4 book ai didi

ios - 如何跳过动画的一部分?

转载 作者:可可西里 更新时间:2023-11-01 01:02:24 25 4
gpt4 key购买 nike

我有一个最初位于位置 A 的 View ,以及另外两个名为 BC 的位置。
此图像显示 View 的初始状态。

enter image description here

我想要实现的是将 View 从 B 动画化到 C但以不同的方式。

我希望动画对象从 A 开始并在 C 结束,但跳过 A→B 部分,只执行 >B→C部分。

代码应该是这样的:

// aLabel and cLabel are the labels shown in the image above
let a = aLabel.center.x
let c = cLabel.center.x

let animation = CABasicAnimation(keyPath: "position.x")
animation.duration = 3

// The animation should start in code from A
animation.fromValue = a

// And ends at C
animation.toValue = c

// Update the model layer
someView.layer.position.x = c

/* ADD SOMETHING TO MAKE THE ANIMATION
STARTS FROM B AND ENDS AT C */

我已经尝试过的

我尝试将动画偏移设置为 1.5 :

animation.timeOffset = 1.5

但是没有用。动画执行如下:B → C → A → B ,我只要B → C

最佳答案

要跳转A→B部分,可以将fromValue设置为bLabel center。

animation.fromValue = bLabel.center.x

如果你想保留 fromValuetoValue 设置 repeatDurationtimeOffset:

    animation.timeOffset = 1.5
animation.repeatDuration = 1.5

关于ios - 如何跳过动画的一部分?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34267681/

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