杨锴
2025-04-16 09a372bc45fde16fd42257ab6f78b8deeecf720b
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
//
//  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()
                                }
                }
}