//
|
// Popup_1_View.swift
|
// XQMuse
|
//
|
// Created by 无故事王国 on 2024/8/13.
|
//
|
|
import UIKit
|
import JQTools
|
|
enum Popup_1_State{
|
case fail
|
case success
|
}
|
|
class Popup_1_View: UIView,JQNibView{
|
|
@IBOutlet weak var img_state: UIImageView!
|
@IBOutlet weak var view_content: UIView!
|
@IBOutlet weak var label_times: UILabel!
|
@IBOutlet weak var label_title: UILabel!
|
@IBOutlet weak var label_subTitle: UILabel!
|
|
private var completeClouse:(()->Void)!
|
override func awakeFromNib() {
|
super.awakeFromNib()
|
|
view_content.transform = .init(scaleX: 0.1, y: 0.1)
|
alpha = 0
|
layoutIfNeeded()
|
}
|
|
static func show(state:Popup_1_State,title:String,subtitle:String, complete:@escaping()->Void){
|
let popupView = Popup_1_View.jq_loadNibView()
|
switch state {
|
case .fail:
|
popupView.img_state.image = UIImage(named: "icon_fail")
|
case .success:
|
popupView.img_state.image = UIImage(named: "icon_success")
|
}
|
popupView.label_title.text = title
|
popupView.label_subTitle.text = subtitle
|
popupView.completeClouse = complete
|
sceneDelegate?.window?.addSubview(popupView)
|
popupView.frame = sceneDelegate?.window?.frame ?? .zero
|
|
var t = 2
|
UIView.animate(withDuration: 0.4) {
|
popupView.alpha = 1
|
popupView.view_content.transform = .init(scaleX: 1.0, y: 1.0)
|
}completion: { _ in
|
Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { _ in
|
t -= 1
|
popupView.label_times.text = "\(min(t,1))s"
|
if t == 0{
|
popupView.hidden()
|
}
|
}
|
}
|
}
|
|
private func hidden(){
|
UIView.animate(withDuration: 0.4) {
|
self.alpha = 0
|
self.view_content.transform = .init(scaleX: 0.1, y: 0.1)
|
}completion: { state in
|
self.removeFromSuperview()
|
self.completeClouse()
|
}
|
}
|
}
|