Анимация сразу заканчивается и не запускает UIView.animate - PullRequest
0 голосов
/ 08 мая 2020

Мой код здесь вообще не работает. Я хочу, чтобы анимация индикатора выполнения снижалась, и я начинаю индикатор выполнения с 1.0, и я хочу, чтобы он был от go до 0 справа налево. Как я могу sh этого добиться? Это просто работает и сразу же заканчивается. Спасибо

UIView.animate(withDuration: 15, animations: {

                        //if (self.answerButtonOne.isSelected == true || self.answerButtonTwo.isSelected == true || self.answerButtonThree.isSelected == true || self.answerButtonFour.isSelected == true  ){
                            //self.view.layer.removeAllAnimations()
                        //}
                    }, completion: { (Bool) in
                        if Bool == true{
                           self.disableButtons()
                            self.showRightChoice()
                            let wrong:Int = UserDefaults.standard.integer(forKey: "wrong")
                            let newWrong = wrong-1
                            UserDefaults.standard.set(newWrong, forKey: "wrong")
                            self.whichImage(newWrong: newWrong)
                            self.gameOver()
                            self.wasButtonClicked = true

                        }
                        self.progressView.setProgress(0.0, animated: true)
                    })

1 Ответ

2 голосов
/ 08 мая 2020
    var timer = Timer()
    var totalDuration = 150.0 // to run it smooth 150/10 = 15

    override func viewDidAppear(_ animated: Bool) {

          self.timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(self.decrementProgress), userInfo: nil, repeats: true)
      }
      @objc func decrementProgress() {
        if totalDuration == 0 {

        }else {

            self.totalDuration -= 1
            self.progress.setProgress(0.0066 * Float(self.totalDuration) , animated: true)
        }
    }
...