7

我弄乱了UIViewPropertyAnimator的文档,我希望找到一种方法来组合两个 UIViewPropertyAnimator。

像这样的东西:

let firstAnimator = UIViewPropertyAnimator(
   duration: 2, 
   dampingRatio: 0.4, 
   animations: animation1
)

let secondAnimator = UIViewPropertyAnimator(
    duration: 2, 
    dampingRatio: 0.4,
    animations: animation2
)

firstAnimator.addAnimator(secondAnimator, withDelay: 1)
firstAnimator.startAnimation()

我缺少 UIViewPropertyAnimatorGroup 或类似的东西,这甚至存在吗?

4

1 回答 1

3

UIViewPropertyAnimator当前推荐的方法是使用's数组。

这种方法在 WWDC 2017 演示文稿中详细概述,标题为“使用 UIKit 的高级动画”。https://developer.apple.com/videos/play/wwdc2017/230/

最重要的一点是将所有动画师放在一起,每当发生基于手势的事件时,您都可以一次将更新应用到所有动画师。

var runningAnimators = [UIViewPropertyAnimator]()

// later in the code...

runningAnimators.forEach { $0.pauseAnimation() } // pause all animations

我在 GitHub 上有一个开源 repo,它给出了以这种方式使用多个属性动画器的示例:https ://github.com/nathangitter/interactive-animations


对于您的具体问题,为什么需要多个属性动画师?通常,当您想要具有多个时序曲线的单个动画时,您只需要多个动画师,但看起来您的时序参数是相同的。

于 2017-11-09T17:56:51.893 回答