我希望堆栈视图的排列子视图以级联方式可见,但它们都同时出现:
let i = 5
let animation = UIViewPropertyAnimator(duration: 5, timingParameters: UICubicTimingParameters())
animation.addAnimations {
UIView.animateKeyframes(withDuration: 0, delay: 0, options: .calculationModeCubicPaced) {
for index in 0..<i {
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: Double(1/i)) {
let label = self.stackView.arrangedSubviews[index]
label.alpha = 1
}
}
} completion: { (_) in
return
}
}
animation.startAnimation()
我的期望是,即使我没有单独设置参数(并将它们设置为 0),也可以以均匀间隔的方式为每个关键帧设置选项calculationModePaced
或为其设置动画。calculationModeCubicPaced
withRelativeStartTime
我尝试将选项更改为calculationModeLinear
并手动设置withRelativeStartTime
:
UIView.addKeyframe(withRelativeStartTime: 0, relativeDuration: 0.5) {
let label = self.stackView.arrangedSubviews[0]
label.alpha = 1
}
UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5) {
let label = self.stackView.arrangedSubviews[1]
label.alpha = 1
}
但是,标签仍然同时出现。