Try it:
UIView.animateWithDuration(1.0, animations: { () -> Void in self.view.backgroundColor = UIColor.blackColor() }) { (Bool) -> Void in UIView.animateWithDuration(1.0, animations: { () -> Void in self.view.backgroundColor = UIColor.greenColor() }, completion: { (Bool) -> Void in UIView.animateWithDuration(1.0, animations: { () -> Void in self.view.backgroundColor = UIColor.grayColor() }, completion: { (Bool) -> Void in UIView.animateWithDuration(1.0, animations: { () -> Void in self.view.backgroundColor = UIColor.redColor() }, completion:nil) }) }) }
If you need continuous looping animation, try this:
UIView.animate(withDuration: 2, delay: 0.0, options:[UIView.AnimationOptions.repeat, UIView.AnimationOptions.autoreverse], animations: { self.view.backgroundColor = UIColor.black self.view.backgroundColor = UIColor.green self.view.backgroundColor = UIColor.darkGray self.view.backgroundColor = UIColor.red }, completion: nil)
source share