60 lines
2.0 KiB
Swift
60 lines
2.0 KiB
Swift
//
|
||
// NW_LauncVC.swift
|
||
// wallpaper_BProject
|
||
//
|
||
// Created by 忆海16 on 2024/9/2.
|
||
//
|
||
|
||
import UIKit
|
||
|
||
class NW_LauncVC: UIViewController {
|
||
private var progressView: UIProgressView!
|
||
private var timer: Timer?
|
||
private var progress: Float = 0.0
|
||
private let totalDuration: TimeInterval = 10.0
|
||
override func viewDidLoad() {
|
||
super.viewDidLoad()
|
||
|
||
setupProgressView()
|
||
startProgress()
|
||
}
|
||
|
||
private func setupProgressView() {
|
||
// 初始化进度条
|
||
progressView = UIProgressView(progressViewStyle: .default)
|
||
progressView.frame = CGRect(x: 50, y: UIScreen.main.bounds.maxY - 36, width: self.view.frame.width - 100, height: 20)
|
||
progressView.progress = 0.0
|
||
progressView.tintColor = .black
|
||
progressView.trackTintColor = .lightGray
|
||
view.addSubview(progressView)
|
||
}
|
||
|
||
private func startProgress() {
|
||
// 每秒更新一次进度条
|
||
timer = Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(updateProgress), userInfo: nil, repeats: true)
|
||
}
|
||
|
||
@objc private func updateProgress() {
|
||
// 计算每秒应增加的进度
|
||
let increment = 1.0 / Float(totalDuration)
|
||
|
||
if progress < 1.0 {
|
||
progress += increment
|
||
progressView.setProgress(progress, animated: true)
|
||
} else {
|
||
// 进度完成,停止计时器
|
||
timer?.invalidate()
|
||
timer = nil
|
||
// 获取应用程序的窗口
|
||
if let window = UIApplication.shared.windows.first {
|
||
// 创建一个新的视图控制器
|
||
let vc = NW_RootTabBarVC()
|
||
window.rootViewController = NW_RootNAVC(rootViewController: vc)
|
||
// 使窗口可见
|
||
window.makeKeyAndVisible()
|
||
}
|
||
}
|
||
}
|
||
|
||
}
|