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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//
//  VoiceHandleView.swift
//  DolphinEnglishLearnStudent
//
//  Created by 无故事王国 on 2024/6/11.
//
 
import UIKit
 
class VoiceHandleView: UIView {
 
                private lazy var img_hint:UIImageView = {
                                let img = UIImageView(image: UIImage(named: "icon_play_1"))
                                return img
                }()
 
                private lazy var img_hint_playing:UIImageView = {
                                let img = UIImageView(image: UIImage(named: "icon_playing"))
                                img.isHidden = true
                                return img
                }()
 
                private lazy var btn_play:UIButton = {
                                let btn = UIButton(type: .custom)
                                btn.setImage(UIImage(named: "icon_play"), for: .normal)
                                return btn
                }()
 
                var playUrl:String?
                var listenType:ListenType?
                private var playAtClouse:((Int)->Void)?
 
                override init(frame: CGRect) {
                                super.init(frame: frame)
                                setUI()
 
                                VoicePlayer.share().playEnd {
                                                self.resetView()
                                }
                }
 
                private func setUI(){
                                backgroundColor = UIColor(hexString: "#41A2EB")
                                jq_cornerRadius = 8
                                addSubview(img_hint)
                                img_hint.snp.makeConstraints { make in
                                                make.left.equalTo(25)
                                                make.centerY.equalToSuperview()
                                                make.width.equalTo(27)
                                                make.height.equalTo(27)
                                }
 
                                addSubview(img_hint_playing)
                                img_hint_playing.snp.makeConstraints { make in
                                                make.center.equalToSuperview()
                                                make.width.equalTo(45)
                                                make.height.equalTo(31)
                                }
 
                                addSubview(btn_play)
                                btn_play.isUserInteractionEnabled = false
                                btn_play.snp.makeConstraints { make in
                                                make.right.equalTo(-23)
                                                make.centerY.equalToSuperview()
                                                make.width.equalTo(32)
                                                make.height.equalTo(32)
                                }
 
                                let playBtn = UIButton(type: .custom)
                                playBtn.addTarget(self, action: #selector(playingAction), for: .touchUpInside)
                                addSubview(playBtn)
                                playBtn.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
                }
 
                required init?(coder: NSCoder) {
                                fatalError("init(coder:) has not been implemented")
                }
 
                func copyView()->VoiceHandleView{
                                let copyView = VoiceHandleView()
                                copyView.listenType = self.listenType
                                copyView.playUrl = self.playUrl
                                copyView.frame = self.frame
                                return copyView
                }
 
                func resetView(){
                                img_hint.isHidden = false
                                btn_play.isHidden = false
                                img_hint_playing.isHidden = true
                }
 
                func playing(){
                                img_hint.isHidden = true
                                btn_play.isHidden = true
                                img_hint_playing.isHidden = false
                }
 
                func playAt(_ clouse:@escaping(Int)->Void){
                                self.playAtClouse = clouse
                }
 
                @objc func playingAction(){
                                if let url = playUrl{
                                                playAtClouse?(self.tag)
                                                VoicePlayer.share().playerAt(url: url)
                                                playing()
                                }
                }
 
}