gpt4 book ai didi

swift - AnimateKeyframes 同时运行所有关键帧 (Swift)

转载 作者:行者123 更新时间:2023-11-30 10:46:10 24 4
gpt4 key购买 nike

我正在尝试对标签进行动画处理,以在不同关键帧处使用不同的单词更改其文本,但它只是跳到最后一个关键帧(“晚安”),而不显示之前的关键帧。它确实打印了它们,所以我猜持续时间或开始时间有问题,但我不知道它可能是什么..

func changeText() {

let options = UIView.KeyframeAnimationOptions.calculationModeLinear

UIView.animateKeyframes(withDuration: 10, delay: 0, options: options, animations: {

UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.25, animations: {
self.label.text = "Good Morning"
print("Morning")
})

UIView.addKeyframe(withRelativeStartTime: 0.25, relativeDuration: 0.25, animations: {
self.label.text = "Good Afternoon"
print("Afternoon")
})

UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.25, animations: {
self.label.text = "Good Evening"
print("Evening")
})
UIView.addKeyframe(withRelativeStartTime: 0.75, relativeDuration: 0.25, animations: {
self.label.text = "Good Night"
print("Night")
})

}, completion: nil)
}

@IBAction func didPressBtn(_ sender: Any) {
changeText()
}

最佳答案

这应该能达到你的目的吗?

 func changeText() {

label.text = "Good Morning"
print("Morning")
sleep(2.5)

label.text = "Good Afternoon"
print("Morning")
sleep(2.5)

label.text = "Good Evening"
print("Morning")
sleep(2.5)

label.text = "Good Night"
print("Morning")
sleep(2.5)

}

关于swift - AnimateKeyframes 同时运行所有关键帧 (Swift),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55728867/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com