// // GuideViewController.swift // Meterage // // Created by 203 on 2023/2/1. // import UIKit import DefaultsKit class GuideViewController: UIViewController { @IBOutlet var skipButton: UIButton! private var timer: Timer? private var countSeconds = 3 override func viewDidLoad() { super.viewDidLoad() timer = Timer.scheduledTimer( timeInterval: 1, target: self, selector: #selector(countDownTimer), userInfo: nil, repeats: true ) // 设置默认ip Defaults.shared.set("http://111.198.10.15:21609", for: serverConfigKey) } // 设置状态栏文字为浅色(白色) override var preferredStatusBarStyle: UIStatusBarStyle { .lightContent } // 倒计时 @objc func countDownTimer() { if countSeconds < 1 { timer?.invalidate() timer = nil toLogin() return } countSeconds -= 1 // 设置按钮在倒计时的时候字体不跳动 skipButton.titleLabel?.text = "跳过 \(countSeconds)s" skipButton.setTitle("跳过 \(countSeconds)s", for: .normal) } @IBAction func skipCountDown(_ sender: UIButton) { timer?.invalidate() timer = nil toLogin() } @objc func toLogin() { let destinationController = LoginViewController(nibName: "LoginViewController", bundle: nil) destinationController.modalPresentationStyle = UIModalPresentationStyle.fullScreen destinationController.modalTransitionStyle = UIModalTransitionStyle.crossDissolve present(destinationController, animated: true, completion: nil) } }