user5623030
user5623030

Reputation:

Animate color of UIView

I use Swift 2 and Xcode 7.1

I wonder how to perform nested animations? Actually i want to annimation that will change the color of my sight gradually. The view will: red -> blue -> green -> red -> ...

This is my code :

func animate(){
    UIView.animateWithDuration(1.0, animations: {
        //self.lbl.transform = CGAffineTransformMakeRotation(0.5)
        self.circle.backgroundColor = UIColor(red: 0.93, green: 0.89, blue: 0.27, alpha: 1)
        }, completion: {
            (value: Bool) in
            UIView.animateWithDuration(1.0, animations: {
                //self.lbl.transform = CGAffineTransformMakeRotation(0.5)
                self.circle.backgroundColor = UIColor(red: 0.3, green: 0.2, blue: 0.7, alpha: 1)
                }, completion: {
                    (value: Bool) in
                    self.animate()
            })
    })
}

Upvotes: 2

Views: 904

Answers (1)

Oleg Gordiichuk
Oleg Gordiichuk

Reputation: 15512

For nested of the animations you should use options of the UIView.animateWithDuration they are Repeat and in this case Autoreverse

  UIView.animateWithDuration(2.0, delay:0, options: [.Repeat, .Autoreverse], animations: {

           //execute animation changes hear

            }, completion: nil)

Upvotes: 1

Related Questions