无故事王国
2025-08-10 510991a68acc59e22602d95582e3b1cabdd093c2
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
//
//  ListenFight_Game_Pocket_CCell.swift
//  DolphinEnglishLearnStudent
//
//  Created by 无故事王国 on 2024/5/29.
//
 
import UIKit
import JQTools
 
class ListenFight_Game_Pocket_CCell: UICollectionViewCell {
 
                enum PocketEnum{
                                case toFrom
                                case toback
                }
 
                lazy var mask_img:UIImageView = {
                                let image = UIImageView(image: UIImage(named: "bg_card"))
                                return image
                }()
 
                lazy var answer_img:UIImageView = {
                                let image = UIImageView()
                                image.jq_cornerRadius  = 10
                                image.backgroundColor = .red
                                return image
                }()
 
 
                lazy var voice_view:UIView = {
                                                let voiceView = UIView()
                                voiceView.backgroundColor = UIColor(hexString: "#41A2EB")
                                voiceView.jq_cornerRadius = 10
                                return voiceView
                }()
 
                let img1 = UIImageView(image: UIImage(named: "icon_play_1")!.withTintColor(UIColor(hexString: "#41A2EB")!))
                let img2 = UIImageView(image: UIImage(named: "icon_playing")!.withTintColor(UIColor(hexString: "#41A2EB")!))
 
                private var pocketEnum = PocketEnum.toback
 
                let stateImg = UIImageView()
 
                let playBtn = UIButton(type: .custom)
 
                private var model:SimpleListenDataModel!
 
                var indexPath:IndexPath!
                private var playIndexClouse:((IndexPath)->Void)?
 
                override init(frame: CGRect) {
                                super.init(frame: frame)
                                addSubview(answer_img)
                                answer_img.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
 
 
                                addSubview(voice_view)
                                voice_view.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
 
                                addSubview(mask_img)
                                mask_img.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
 
                                let contentVoiceView = UIView()
                                contentVoiceView.backgroundColor = .white
                                contentVoiceView.jq_cornerRadius = 8
                                voice_view.addSubview(contentVoiceView)
                                contentVoiceView.snp.makeConstraints { make in
                                                make.center.equalToSuperview()
                                                make.width.equalTo(self.width * 0.66)
                                                make.height.equalTo(self.height * 0.32)
                                }
 
                                contentVoiceView.addSubview(img1)
                                img1.snp.makeConstraints { make in
                                                make.left.equalTo(self.width * 0.0958)
                                                make.width.height.equalTo(self.width * 0.133)
                                                make.centerY.equalToSuperview()
                                }
 
 
                                contentVoiceView.addSubview(img2)
                                img2.snp.makeConstraints { make in
                                                make.width.equalTo(self.width * 0.1875)
                                                make.height.equalTo(self.width * 0.1292)
                                                make.center.equalToSuperview()
                                }
 
                                playBtn.addTarget(self, action: #selector(playAction), for: .touchUpInside)
                                playBtn.setBackgroundImage(UIImage(named: "icon_play")?.withTintColor(UIColor(hexString: "#41A2EB")!), for: .normal)
                                playBtn.isEnabled = false
                                contentVoiceView.addSubview(playBtn)
                                playBtn.snp.makeConstraints { make in
                                                make.right.equalTo(-self.width * 0.0958)
                                                make.width.height.equalTo(self.width * 0.133)
                                                make.centerY.equalToSuperview()
                                }
 
                                addSubview(stateImg)
                                stateImg.snp.makeConstraints { make in
                                                make.center.equalToSuperview()
                                                make.width.height.equalTo(self.width * 0.316)
                                }
 
                                cellResotePay()
                }
 
                func cellResotePay(){
                                img2.isHidden = true
                                img1.isHidden = false
                                playBtn.isHidden = false
                                layoutIfNeeded()
                }
 
                func cellPlaying(){
                                img2.isHidden = false
                                img1.isHidden = true
                                playBtn.isHidden = true
                                playIndexClouse?(indexPath)
                }
 
                func setState(success:Bool){
                                if success{
                                                stateImg.image = UIImage(named: "icon_success")
                                }else{
                                                stateImg.image = UIImage(named: "icon_fail")
                                }
 
 
                                stateImg.alpha = 0
                                stateImg.transform = .init(scaleX: 0.1, y: 0.1)
                                layoutIfNeeded()
 
                                UIView.animate(withDuration: 0.4) {
                                                self.stateImg.alpha = 1
                                                self.stateImg.transform = .init(scaleX: 1.0, y: 1.0)
                                } completion: { state in
                                                if state{
                                                                DispatchQueue.main.asyncAfter(wallDeadline: .now()+0.5){
                                                                                UIView.animate(withDuration: 0.5) {
                                                                                                self.stateImg.alpha = 0
                                                                                                self.stateImg.transform = .init(scaleX: 0.1, y: 0.1)
                                                                                }
                                                                }
                                                }
                                }
 
                }
 
                func cellPayatIndex(_ clouse:@escaping (IndexPath)->Void){
                                self.playIndexClouse = clouse
                }
 
                @objc func playAction(){
                                //防止穿透点击播放
                                if pocketEnum == .toFrom{
                                                VoicePlayer.share().playerAt(url: model.voice)
                                                cellPlaying()
                                }
                }
 
                func setSimpleModel(_ model:SimpleListenDataModel){
                                self.model = model
                                if model.type == 1{
                                                voice_view.isHidden = true
                                                answer_img.sd_setImage(with: URL(string: model.photo))
                                }else{
                                                voice_view.isHidden = false
                                }
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
 
                func toFromAction(_ superView:UIView? = nil,c:Bool? = nil){
                                superView?.isUserInteractionEnabled = false
                                pocketEnum = .toFrom
                                playBtn.isEnabled = true
                                UIView.transition(from: mask_img, to: answer_img, duration: 0.6, options: [.transitionFlipFromLeft,.showHideTransitionViews]) { _ in
                                                if c == true{
                                                                superView?.isUserInteractionEnabled = true
                                                }
                                }
                }
 
                func toBackAction(_ superView:UIView? = nil,c:Bool? = nil){
                                superView?.isUserInteractionEnabled = false
                                pocketEnum = .toback
                                playBtn.isEnabled = false
                                UIView.transition(from: answer_img, to: mask_img, duration: 0.6,options: [.transitionFlipFromRight,.showHideTransitionViews]){ _ in
                                                if c == true{
                                                                superView?.isUserInteractionEnabled = true
                                                }
                                }
                }
}