I'm trying to animate a label to change its text with different words at different keyframes, but it just skips to the last keyframe ("Good Night") without displaying the previous ones. It does print them out so I guess there is something wrong with either the duration or startTime but I can't figure out what it could be..
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()
}