0

我正在寻找一种将一些动画添加到一个比其他动画UIViewPropertyAnimator更早完成的方法。 UIViewPropertyAnimator例如,有一种方法可以延迟添加动画

animator.addAnimations(animation: (()-> Void), delayFactor: CGFloat)

所以动画在 adelayFactor的50% 处开始0.5

我搜索类似的东西

animator.addAnimations(animation: (()->Void), realtiveDuration: CGFloat)

所以动画在 50% 的持续时间后relativeDuration结束0.5

经过一番研究,我找到了一个解决方案

animator.addAnimations {
    UIView.animateKeyframes(withDuration: duration, delay: 0.0, animations: {
        UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.3) {
            view.alpha = 0.0
        }
    })
}

存档此行为。问题是,我想在某种自动化中使用它,我迭代一些元素并为每个元素调用一个方法:

func animation(view: UIView) -> (() -> Void) {
    return {
        view.alpha = 0.0
    }
}

使用例如该方法时效果很好

animator.addAnimations(animation: element.animation(element.view), delayFactor: 0.5) 但我不能在里面调用它

.addKeyframe(...){
    element.animation(element.view)
}

也许你们中的一些人有解决方案?我正在考虑覆盖UIViewPropertyAnimator例如添加所询问的方法animator.addAnimations(animation: (()->Void), realtiveDuration: CGFloat)或其他内容,但将我的舒适区留在那里。

4

1 回答 1

1

你可以这样调用:

  UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5, animations: element.animation(element.view))
于 2019-03-22T23:01:02.310 回答