Here's a working example, just change the colors:
var backgroundColours = [UIColor()]
var backgroundLoop = 0
override func viewDidLoad() {
super.viewDidLoad()
backgroundColours = [UIColor.redColor(), UIColor.blueColor(), UIColor.yellowColor()]
backgroundLoop = 0
self.animateBackgroundColour()
}
func animateBackgroundColour () {
if backgroundLoop < backgroundColours.count - 1 {
backgroundLoop++
} else {
backgroundLoop = 0
}
UIView.animateWithDuration(1, delay: 0, options: UIViewAnimationOptions.AllowUserInteraction, animations: { () -> Void in
self.view.backgroundColor = self.backgroundColours[self.backgroundLoop];
}) {(Bool) -> Void in
self.animateBackgroundColour();
}
}
This will cycle through colors endlessly, so you change up the looping mehanism, and the method will continuously call itself until you issue a command to remove all animations.