My code below is a timer. Once 2 seconds is reached a button appears. Right now if you press the button disappears forever. I would like the button to reappear after 10 seconds. After 10 seconds is passed I would like to override the action of making the button disappear if selected within the 2 and 9 range. So if someone hits a button between 2 and 9 seconds. I would like the button to automatically reappear after 10 seconds.
import UIKit
class ViewController: UIViewController {
@IBOutlet var Rest: UIButton!
@IBOutlet var start: UIButton!
var timer = Timer()
var counter = 0.0
var isRunning = false
@IBOutlet var dx: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
dx.text = "\(counter)"
start.isEnabled = true
}
@IBAction func play(_ sender: Any) {
if !isRunning{
timer = Timer.scheduledTimer(timeInterval: 0.1, target: self, selector: #selector(ViewController.updateTimer), userInfo: nil, repeats: true)
start.isEnabled = false
isRunning = true
}}
@IBAction func disaper(_ sender: Any) {
Rest.isHidden = true
}
func updateTimer(){
counter += 0.1
dx.text = String(format: "%.1f", counter)
if counter > 2 && counter < 9
{
Rest.alpha = 1
Rest.isEnabled = true
} else if counter > 10 {
Rest.alpha = 1
Rest.isEnabled = true
}
else {
return
Rest.alpha = 0
Rest.isEnabled = false
}}}