Swift 3. Stop UIView.animate

Viewed 4570

I'am trying to learn Swift. I use this 2 functions:

func getRandomColor(){
    let red   = Float((arc4random() % 256)) / 255.0
    let green = Float((arc4random() % 256)) / 255.0
    let blue  = Float((arc4random() % 256)) / 255.0
    let alpha = Float(1.0)
    colours = UIColor(colorLiteralRed: red, green: green, blue: blue, alpha: alpha)

    UIView.animate(withDuration: 2, delay: 1.0, options:[UIViewAnimationOptions.repeat, UIViewAnimationOptions.autoreverse], animations: {
        self.view.backgroundColor = self.colours}, completion:nil)
}

func updateTimer(){
        if seconds! == 0 {
            timer.invalidate()
            isTimerRunning = false
        }
        else {
            seconds! -= 1
            timerLabel.text = timeString(time: TimeInterval(seconds!))
        }
        if seconds! < 55 {
            getRandomColor()
        }
    }

When the seconds = 0, the timer stop, but the animation continue. How can stop the animation when the timer is stoped?

1 Answers
Related