先前从UIViewPropertyAnimator完成一些动画

问题描述 投票:0回答:1

我寻找一种方法来添加一些动画到UIViewPropertyAnimator,然后比其他人早完成。例如,UIViewPropertyAnimator有一种方法可以添加延迟动画

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

所以动画在delayFactor0.5的持续时间的50%开始。

我搜索类似的东西

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

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

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

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

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

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)或其他东西,但留下我的comfortzone。

ios swift animation duration uiviewpropertyanimator
1个回答
1
投票

你可以这样打电话:

  UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5, animations: element.animation(element.view))
© www.soinside.com 2019 - 2024. All rights reserved.