I need to implement a smooth transition to another View
using a timer.
For example, when I click on the start button and after 15 seconds pass, the automatic transition to another View
takes place.
I need to implement a smooth transition to another View
using a timer.
For example, when I click on the start button and after 15 seconds pass, the automatic transition to another View
takes place.
In start button action start a timer with an incrementing counter variable. In the timer execution block if the count reaches 15, invalidate the timer and navigate to next view controller
@objc func startBtnAction(_ sender: UIButton) {
var count = 0
let target = 15
Timer.scheduledTimer(withTimeInterval: 1, repeats: true) { [weak self] timer in
self?.label.text = String(format: "%02d:%02d", count/60,count%60)
if count == target {
timer.invalidate()
self?.performSegue(withIdentifier: "NextScreen", sender: self)
} else {
count += 1
}
}
}