fix
无故事王国
2024-06-20 0c89e362069e2f97d18a01a3a82835ef37a34d18
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
//
//  ListenFight_Game_Pocket_CCell.swift
//  DolphinEnglishLearnStudent
//
//  Created by 无故事王国 on 2024/5/29.
//
 
import UIKit
import JQTools
 
class ListenFight_Game_Pocket_CCell: UICollectionViewCell {
 
                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")!))
                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.left.equalTo(40)
                                                make.right.equalTo(-40)
                                                make.top.equalTo(55)
                                                make.bottom.equalTo(-55)
                                }
 
                                contentVoiceView.addSubview(img1)
                                img1.snp.makeConstraints { make in
                                                make.left.equalTo(23)
                                                make.width.height.equalTo(32)
                                                make.centerY.equalToSuperview()
                                }
 
 
                                contentVoiceView.addSubview(img2)
                                img2.snp.makeConstraints { make in
                                                make.width.equalTo(45)
                                                make.height.equalTo(31)
                                                make.center.equalToSuperview()
                                }
 
                                playBtn.addTarget(self, action: #selector(playAction), for: .touchUpInside)
                                playBtn.setImage(UIImage(named: "icon_play")?.withTintColor(UIColor(hexString: "#41A2EB")!), for: .normal)
                                contentVoiceView.addSubview(playBtn)
                                playBtn.snp.makeConstraints { make in
                                                make.right.equalTo(-23)
                                                make.width.height.equalTo(32)
                                                make.centerY.equalToSuperview()
                                }
                                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 cellPayatIndex(_ clouse:@escaping (IndexPath)->Void){
                                self.playIndexClouse = clouse
                }
 
                @objc func playAction(){
                                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")
                }
 
                @objc func toFromAction(_ superView:UIView? = nil){
                                superView?.isUserInteractionEnabled = false
                                UIView.transition(from: mask_img, to: answer_img, duration: 0.6, options: [.transitionFlipFromLeft,.showHideTransitionViews]) { _ in
                                                superView?.isUserInteractionEnabled = true
                                }
                }
 
                @objc func toBackAction(_ superView:UIView? = nil){
                                superView?.isUserInteractionEnabled = false
                                UIView.transition(from: answer_img, to: mask_img, duration: 0.6,options: [.transitionFlipFromRight,.showHideTransitionViews]){ _ in
                                                superView?.isUserInteractionEnabled = true
                                }
                }
}