// // LunchViewController.swift // MusicPlayer // // Created by Mr.Zhou on 2024/3/27. // import UIKit ///启动页 class MP_LunchViewController: UIViewController { @IBOutlet weak var progressView: MP_Lunch_ProgressView!{ didSet{ progressView.layer.masksToBounds = true } } //帧计时器 private var timer:CADisplayLink! //最大计时值 private lazy var maxTimes:TimeInterval = 8 //当前计时值 private lazy var currentTimes:TimeInterval = 0 override func viewDidLoad() { super.viewDidLoad() view.backgroundColor = .init(hex: "#000000") timer = CADisplayLink(target: self, selector: #selector(timerActionClick(_ :))) //一秒执行多少次 timer.preferredFramesPerSecond = 20 //开辟线程 timer.add(to: RunLoop.current, forMode: .common) //启动计时器 timer.isPaused = false //获取定位权限 MP_LocationManager.shared.setLocationPermission(self, complete: nil) //获取youtube网站信息 MP_WebWork.shared.pingYoutubeHome() } deinit { //销毁计时器 timer.invalidate() timer = nil } //计时器执行事件 @objc fileprivate func timerActionClick(_ link:CADisplayLink) { if maxTimes > currentTimes { //未加载完 currentTimes += 0.05 let value = currentTimes/maxTimes DispatchQueue.main.async { [weak self] in guard let self = self else {return} //设置进度条 progressView.setProgress(value) } }else { DispatchQueue.main.async { [weak self] in guard let self = self else {return} //停止计时器 timer.isPaused = true //加载完毕,判断并跳转 // accessAppdelegate.switch_aSide() accessAppdelegate.switch_positive() } } } }