我正在寻找一种将动画添加到UIViewPropertyAnimator
的方法,该动画要比其他动画更早完成。
UIViewPropertyAnimator
例如具有一种可以延迟添加动画的方法
animator.addAnimations(animation: (()-> Void), delayFactor: CGFloat)
所以动画在delayFactor
的{{1}}处以持续时间的50%开始。
我搜索类似
0.5
因此动画在animator.addAnimations(animation: (()->Void), realtiveDuration: CGFloat)
的{{1}}的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)
}
之类的东西,但是将我的舒适区保留在那里。
答案 0 :(得分:1)
您可以这样称呼:
UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5, animations: element.animation(element.view))