I have a UIView that is a countdown clock, which I animate with UIView.animate. There is also a running timer that shows the time on a UILabel, when the timer is fired. When the game is in transition (during the count down), the UILabel stops changing. I've put a "print" statement into the timer function and it shows up as expected.
I've been searching for hints about maybe the UIVIew.animate freezes other views, but I see multiple apps moving views at the same time. Maybe I'm supposed to put things on different thread?
@objc func timerUpdate () {
if gameIsRunning {
let endTime = Date.init()
let difference = endTime.timeIntervalSince(gameClock)
let formattedString = String(format: "%3.1f",kDefaultGameClock - difference)
timerLabel.text = "\(formattedString)"
}
}
private func countDownFrom (x: Int) {
if x != 0 && x > 0 {
UIView.animate(withDuration: 1.0,
delay: 0.0,
usingSpringWithDamping: 0.5,
initialSpringVelocity:1.0,
options: .curveEaseOut,
animations: {
self.successLabel.text = "\(x)"
self.successLabel.transform = self.successLabel.transform.scaledBy(x: 4.0, y: 4.0)
}, completion: {_ in
self.successLabel.transform = self.successLabel.transform.scaledBy(x: 0.250, y: 0.250)
if (x - 1 > 0) {
self.countDownFrom(x: x - 1)
} else {
self.successLabel.text = kDefaultGoodGame
self.successLabel.isHidden = true
self.startTheGame()
self.updateScreen()
}
})
}
}
timerUpdate
?countDownFrom
looks fine. – Derek