杨锴
2025-05-11 7453d2d0cef415b34323d1b91e6cfa4a6ba31178
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
//
//  GamesPayView.swift
//  WanPai
//
//  Created by 无故事王国 on 2023/9/15.
//
 
import UIKit
import JQTools
 
class GamesPayView: UIView,JQNibView{
 
    @IBOutlet weak var view_container: UIView!
    @IBOutlet weak var label_price: UILabel!
    @IBOutlet weak var label_coin: UILabel!
    @IBOutlet weak var label_integral: UILabel!
    
    private var price:Double = 0
    private var coin:Int?
    private var integral:Int?
    private var needPay:(()->Void)!
 
    override func awakeFromNib() {
        super.awakeFromNib()
        label_coin.isHidden = true
        label_integral.isHidden = true
        label_price.isHidden = true
        view_container.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
        alpha = 0
        layoutIfNeeded()
    }
 
    static func show(price:Double,coin:Int?,integral:Int? = nil,needPay: @escaping ()->Void){
        let gamesPayView = GamesPayView.jq_loadNibView()
        gamesPayView.frame = sceneDelegate?.window?.frame ?? .zero
        gamesPayView.price = price
        gamesPayView.coin = coin
        gamesPayView.integral = integral
        gamesPayView.needPay = needPay
 
        if price != 0 && price != 0{
            gamesPayView.label_price.isHidden = false
            gamesPayView.label_price.attributedText    = AttributedStringbuilder.build().add(string: "游玩价格:", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: .black.withAlphaComponent(0.8)).add(string: price.currency(), withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: Def_ThemeColor).mutableAttributedString
        }
 
 
        if coin != nil && coin != 0{
            gamesPayView.label_coin.isHidden = false
            gamesPayView.label_coin.attributedText    = AttributedStringbuilder.build().add(string: "玩湃币:", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: .black.withAlphaComponent(0.8)).add(string: "\(coin!)币", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: Def_ThemeColor).mutableAttributedString
        }
 
        if integral != nil && integral != 0{
            gamesPayView.label_integral.isHidden = false
            gamesPayView.label_integral.attributedText    = AttributedStringbuilder.build().add(string: "积分:", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: .black.withAlphaComponent(0.8)).add(string: "\(integral!)", withFont: UIFont.systemFont(ofSize: 16, weight: .medium), withColor: Def_ThemeColor).mutableAttributedString
        }
 
 
        sceneDelegate?.window?.addSubview(gamesPayView)
        UIView.animate(withDuration: 0.5) {
            gamesPayView.view_container.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
            gamesPayView.alpha = 1
        } completion: { _ in
 
        }
    }
 
    @IBAction func payAction(_ sender: UIButton) {
        needPay()
        cancel()
    }
 
    @IBAction func closeAction(_ sender: UIButton) {
        cancel()
    }
 
    private func cancel(){
        UIView.animate(withDuration: 0.5) {
            self.view_container.transform = CGAffineTransform(scaleX: 0.1, y: 0.1)
            self.alpha = 0
            self.layoutIfNeeded()
        } completion: { _ in
            self.removeFromSuperview()
        }
    }
}