Music_Player3/MusicPlayer/MP/Common/Base(公用基类)/Controllers/MP_LunchViewController.swift
2024-05-14 15:04:59 +08:00

81 lines
2.6 KiB
Swift
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//
// 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()
NotificationCenter.notificationKey.add(observer: self, selector: #selector(jumpAction(_:)), notificationName: .js_edit_completion)
}
deinit {
//
timer.invalidate()
timer = nil
NotificationCenter.default.removeObserver(self)
}
@objc private func jumpAction(_ sender:Notification) {
DispatchQueue.main.async {
[weak self] in
guard let self = self else {return}
//
timer.isPaused = true
//
accessAppdelegate.switch_positive()
}
}
//
@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 {
print("进度已满")
// DispatchQueue.main.async {
// [weak self] in
// guard let self = self else {return}
// //
// timer.isPaused = true
// //
// accessAppdelegate.switch_positive()
// }
}
}
}