How can I make the background color flash 2 new colors continuously every time the button is pressed? Right now it just shows 2 colors but they don't blink or flash continuously.
import UIKit
class ViewController: UIViewController {
let colors: [UIColor] = [
.systemYellow,
.systemGreen,
.systemPurple,
.systemPink,
.systemRed,
.systemBlue,
.systemOrange,
.black,.gray
]
override func viewDidLoad() {
super.viewDidLoad()
view.backgroundColor = .clear
}
@IBAction func didTapButton() {
UIView.animate(withDuration: 1/2, delay: 0, options: .curveEaseOut, animations: {
self.view.backgroundColor = self.colors.randomElement()
}, completion: { finished in
print("another animation! - 1")
UIView.animate(withDuration: 1/2, delay: 0, options: .curveEaseOut, animations: {
self.view.backgroundColor = self.colors.randomElement()
}, completion: { finished in
print("another animation! - 2")
})
})
}
}