How do I make my animation only use colors in the “colors” array and not use oringal white background as it’s first key frame? Please help
Any way to skip/delete/ the first key frame which is white.
var color1 = UIColor.purple
var color2 = UIColor.blue
var color3 = UIColor.green
var color4 = UIColor.yellow
var color5 = UIColor.orange
extension UIViewController {
func viewDidLoad(){
let colors = [color1, color2, color3, color4, color5]
let totalDuration = 5.0
let relDuration: CGFloat = 1.0 / CGFloat(colors.count)
var relStartTime: TimeInterval = 0.0
UIView.animateKeyframes(withDuration: totalDuration, delay: 0.0, options: [.repeat, .allowUserInteraction, .autoreverse, .calculationModeCubicPaced], animations: {
colors.forEach { c in
UIView.addKeyframe(withRelativeStartTime: relStartTime, relativeDuration: relDuration, animations: {
self.view.backgroundColor = c
})
relStartTime += relDuration
}}
)
}
}
