//
|
// 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?()
|
}
|
}
|
}
|