【问题标题】:How to skip a part of an animation?如何跳过动画的一部分?
【发布时间】:2015-12-14 12:58:06
【问题描述】:

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

我想要实现的是将视图从 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

【问题讨论】:

    标签: ios swift animation core-animation cabasicanimation


    【解决方案1】:

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

    animation.fromValue = bLabel.center.x
    

    如果您想保留fromValuetoValue,请将repeatDurationtimeOffset 一起设置:

        animation.timeOffset = 1.5
        animation.repeatDuration = 1.5
    

    【讨论】:

    • 很抱歉,由于某些原因,我无法更改动画的 fromValue 和 toValue。我需要另一种方法,我在问题中提到我需要一种不同的方法。
    • @SalimBraksa 我编辑了我的答案,检查编辑是否回答了你的问题。
    猜你喜欢
    • 1970-01-01
    • 2012-08-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-20
    相关资源
    最近更新 更多