CNLiveVodLandscapeBeiSuView.swift
7.49 KB
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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//
// CNLiveVodLandscapeBeiSuView.swift
// metaCode
//
// Created by zx on 2025/3/27.
// 横屏倍速
import Foundation
typealias CNLiveVodLandscapeBeiSuUpdateBlock = (_ rate:Float)->Void
class CNLiveVodLandscapeBeiSuView:UIView,UIGestureRecognizerDelegate{
var beiSuUpdateBlock:CNLiveVodLandscapeBeiSuUpdateBlock?
var currSeleIdx = 2//1.0
//MARK: - 懒加载
lazy var titleLabel: UILabel = {
let titleLbl = UILabel()
titleLbl.font = Font_14
titleLbl.textColor = HexColor("#FFFFFF")
titleLbl.text = "倍速"
return titleLbl
}()
override init(frame: CGRect) {
super.init(frame: frame)
self.backgroundColor = HexColor("#000000", alpha: 0.7)
self.isUserInteractionEnabled = true
self.initUI()
self.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(tapAction)))
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
func initUI(){
self.addSubview(self.titleLabel)
titleLabel.snp.makeConstraints { make in
make.top.equalToSuperview().offset(31)
make.centerX.equalToSuperview()
}
var W:CGFloat = 65.0
var H:CGFloat = 65.0
let padding:CGFloat = 18.0
let leftPadding:CGFloat = (KSreenHeight-W*6-padding*5)*0.5
var title = "0.5x"
for i in 0..<6{
let expandBtn = UIButton.init(type: .custom)
expandBtn.frame = CGRect(x: leftPadding+CGFloat(i)*(W+padding), y: 0, width: W, height: H)
expandBtn.centerY = KSreenWidth*0.5
if i == 0{
title = "0.5x"
}else if i == 1{
title = "0.75x"
}else if i == 2{
title = "1.0x"
}else if i == 3{
title = "1.25x"
}else if i == 4{
title = "1.5x"
}else if i == 5{
title = "2.0x"
}
if i == self.currSeleIdx{
expandBtn.backgroundColor = HexColor("#D3E4FF")
expandBtn.layer.borderWidth = 0.65
expandBtn.layer.borderColor = HexColor("#478BFF")?.cgColor
expandBtn.isSelected = true
}else{
expandBtn.backgroundColor = HexColor("#000000")
expandBtn.layer.borderWidth = 0
expandBtn.layer.borderColor = HexColor("#000000")?.cgColor
expandBtn.isSelected = false
}
expandBtn.setTitle(title, for: .normal)
expandBtn.setTitle(title, for: .selected)
expandBtn.setTitleColor(HexColor("#FFFFFF"), for: .normal)
expandBtn.setTitleColor(HexColor("#478BFF"), for: .selected)
expandBtn.titleLabel?.font = Font_18
expandBtn.layer.cornerRadius = 12
expandBtn.clipsToBounds = true
expandBtn.tag = 100+i
expandBtn.addTarget(self, action: #selector(beisuBtnAction), for: .touchUpInside)
self.addSubview(expandBtn)
}
self.initGesture()
}
func initGesture(){
self.isMultipleTouchEnabled = true
// 双击手势
var doubleTapGesture = UITapGestureRecognizer(target: self, action: #selector(doubleTapAction))
doubleTapGesture.numberOfTapsRequired = 2 // 双击触发
doubleTapGesture.delaysTouchesBegan = true
doubleTapGesture.delaysTouchesEnded = true
doubleTapGesture.numberOfTouchesRequired = 1
var panGesture = UIPanGestureRecognizer(target: self, action: #selector(panAction))
panGesture.delaysTouchesBegan = true
panGesture.delaysTouchesEnded = true
panGesture.maximumNumberOfTouches = 1
panGesture.cancelsTouchesInView = true
var tapGesture = UITapGestureRecognizer(target: self, action: #selector(tapAction))
tapGesture.delaysTouchesBegan = true
tapGesture.delaysTouchesEnded = true
tapGesture.numberOfTouchesRequired = 1
tapGesture.numberOfTapsRequired = 1
tapGesture.require(toFail: doubleTapGesture)
tapGesture.require(toFail: panGesture)
self.addGestureRecognizer(tapGesture)
self.addGestureRecognizer(doubleTapGesture)
self.addGestureRecognizer(panGesture)
var pinchGesture = UIPinchGestureRecognizer(target: self, action: #selector(pinchAction))
pinchGesture.delaysTouchesBegan = true
self.addGestureRecognizer(pinchGesture)
// 长按手势
var longGesture = UILongPressGestureRecognizer(target: self, action: #selector(longPressAction))
longGesture.minimumPressDuration = 0.5// 长按触发时间(秒)
self.addGestureRecognizer(longGesture)
}
// @objc func tapAction(){
//// self.isHidden = true
// print("tapAction")
// }
@objc func pinchAction(){
// self.isHidden = true
print("pinchAction")
}
@objc func longPressAction(){
// self.isHidden = true
print("longPressAction")
}
@objc func doubleTapAction(){
// self.isHidden = true
print("doubleTapAction")
}
@objc func panAction(){
// self.isHidden = true
print("panAction")
}
@objc func beisuBtnAction(btn:UIButton){
let btnTag = btn.tag
for obj in self.subviews{
if obj.tag >= 100{
if obj.tag == btnTag{
if let tmpBtn = obj as? UIButton{
tmpBtn.backgroundColor = HexColor("#D3E4FF")
tmpBtn.layer.borderWidth = 0.65
tmpBtn.layer.borderColor = HexColor("#478BFF")?.cgColor
tmpBtn.isSelected = true
}
}else{
if let tmpBtn = obj as? UIButton{
tmpBtn.backgroundColor = HexColor("#000000")
tmpBtn.layer.borderWidth = 0
tmpBtn.layer.borderColor = HexColor("#000000")?.cgColor
tmpBtn.isSelected = false
}
}
}
}
let i = btn.tag-100
var rate:Float = 1.0
if i == 0{
rate = 0.5
}else if i == 1{
rate = 0.75
}else if i == 2{
rate = 1.0
}else if i == 3{
rate = 1.25
}else if i == 4{
rate = 1.5
}else if i == 5{
rate = 2.0
}
self.beiSuUpdateBlock?(rate)
}
@objc func tapAction(){
self.isHidden = true
}
//恢复1倍速
func setDefault1Beisu(){
let btnTag = 102
for obj in self.subviews{
if obj.tag >= 100{
if obj.tag == btnTag{
if let tmpBtn = obj as? UIButton{
tmpBtn.backgroundColor = HexColor("#D3E4FF")
tmpBtn.layer.borderWidth = 0.65
tmpBtn.layer.borderColor = HexColor("#478BFF")?.cgColor
tmpBtn.isSelected = true
}
}else{
if let tmpBtn = obj as? UIButton{
tmpBtn.backgroundColor = HexColor("#000000")
tmpBtn.layer.borderWidth = 0
tmpBtn.layer.borderColor = HexColor("#000000")?.cgColor
tmpBtn.isSelected = false
}
}
}
}
}
}