fix
无故事王国
2024-06-26 46acca18a3d1744e1930f0bac7509a2a5959df1b
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//
//  CommonAlertView.swift
//  DolphinEnglishLearnManager
//
//  Created by 无故事王国 on 2024/5/17.
//
 
import UIKit
 
class CommonAlertView: UIView,JQNibView{
 
                @IBOutlet weak var view_container: UIView!
                @IBOutlet weak var label_content: UILabel!
                @IBOutlet weak var btn_complete: UIButton!
                @IBOutlet weak var btn_close: UIButton!
                @IBOutlet weak var cons_btnClose: NSLayoutConstraint!
                
                private var clouse:(()->Void)?
                private var cancelClouse:(()->Void)?
                override func awakeFromNib() {
                                super.awakeFromNib()
                                self.alpha = 0
                                view_container.transform = .init(scaleX: 0.1, y: 0.1)
                                layoutIfNeeded()
                }
 
                static func show(isSinple:Bool = false, content:String,clouse:( ()->Void)? = nil){
                                 let commonAlertView = CommonAlertView.jq_loadNibView()
                                sceneDelegate?.window?.addSubview(commonAlertView)
                                commonAlertView.label_content.text = content
                                commonAlertView.label_content.numberOfLines = 0
                                commonAlertView.label_content.textAlignment = .center
                                commonAlertView.clouse = clouse
                                commonAlertView.frame = sceneDelegate?.window?.frame ?? .zero
 
                                if isSinple{
                                                commonAlertView.btn_complete.isHidden = true
                                                commonAlertView.cons_btnClose.constant = 219
                                                commonAlertView.btn_close.backgroundColor = Config.ThemeColor
                                                commonAlertView.btn_close.jq_borderWidth = 0
                                                commonAlertView.btn_close.setTitleColor(.white, for: .normal)
                                }
 
                                UIView.animate(withDuration: 0.4) {
                                                commonAlertView.alpha = 1
                                                commonAlertView.view_container.transform = .init(translationX: 1.0, y: 1.0)
                                                commonAlertView.layoutIfNeeded()
                                }
                }
 
                static func showSimple(content:String,completeTitle:String? = nil,cancelClouse:@escaping (()->Void)){
                                let commonAlertView = CommonAlertView.jq_loadNibView()
                                sceneDelegate?.window?.addSubview(commonAlertView)
                                commonAlertView.label_content.text = content
                                commonAlertView.label_content.numberOfLines = 0
                                commonAlertView.label_content.textAlignment = .center
                                commonAlertView.cancelClouse = cancelClouse
                                commonAlertView.frame = sceneDelegate?.window?.frame ?? .zero
 
                                commonAlertView.btn_complete.isHidden = true
                                commonAlertView.cons_btnClose.constant = 219
                                commonAlertView.btn_close.backgroundColor = Config.ThemeColor
                                commonAlertView.btn_close.jq_borderWidth = 0
                                commonAlertView.btn_close.setTitleColor(.white, for: .normal)
 
                                UIView.animate(withDuration: 0.4) {
                                                commonAlertView.alpha = 1
                                                commonAlertView.view_container.transform = .init(translationX: 1.0, y: 1.0)
                                                commonAlertView.layoutIfNeeded()
                                }
                }
 
                @IBAction func closeAction(_ sender: UIButton) {
                                UIView.animate(withDuration: 0.4) {
                                                self.alpha = 0
                                                self.view_container.transform = .init(scaleX: 0.1, y: 0.1)
                                } completion: { _ in
                                                self.removeFromSuperview()
                                                self.cancelClouse?()
                                }
                }
 
                @IBAction func completeAction(_ sender: UIButton) {
                                UIView.animate(withDuration: 0.4) {
                                                self.alpha = 0
                                                self.view_container.transform = .init(scaleX: 0.1, y: 0.1)
                                } completion: { _ in
                                                self.removeFromSuperview()
                                                self.clouse?()
                                }
                }
}