CNLiveVodLandscapeGaoqingView.swift
9.28 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
//
// CNLiveVodLandscapeGaoqingView.swift
// metaCode
//
// Created by zx on 2025/3/28.
// 横屏高清
import Foundation
//标清 2 ,高清 3 ,超清 4
typealias CNLiveVodLandscapeGaoqingUpdateBlock = (_ gaoqing:Int)->Void
class CNLiveVodLandscapeGaoqingView:UIView,UIGestureRecognizerDelegate{
var gaoqingUpdateBlock:CNLiveVodLandscapeGaoqingUpdateBlock?
var currSeleIdx = 1//720
//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)))
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")
}
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 WH:CGFloat = 90.0
let padding:CGFloat = 20.0
let count:Int = 3
let leftPadding:CGFloat = (KSreenHeight-WH*CGFloat(count)-padding*CGFloat(count-1))*0.5
var title = "高清"
var subTitle = "720P"
for i in 0..<count{
let expandBtn = UIButton.init(type: .custom)
expandBtn.frame = CGRect(x: leftPadding+CGFloat(i)*(WH+padding), y: 0, width: WH, height: WH)
expandBtn.centerY = KSreenWidth*0.5
if i == 0{
//标清480
title = "标清"
subTitle = "480P"
}else if i == 1{
//高清720
title = "高清"
subTitle = "720P"
}else if i == 2{
//超清1080
title = "超清"
subTitle = "1080P"
}
expandBtn.setTitle("", for: .normal)
expandBtn.setTitle("", 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(gaoqingBtnAction), for: .touchUpInside)
self.addSubview(expandBtn)
let titleLbl = UILabel()
titleLbl.font = Font_14
titleLbl.text = title
expandBtn.addSubview(titleLbl)
titleLbl.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalToSuperview().offset(30)
}
let subTitleLbl = UILabel()
subTitleLbl.font = Font_10
subTitleLbl.text = subTitle
expandBtn.addSubview(subTitleLbl)
subTitleLbl.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.top.equalTo(titleLbl.snp.bottom).offset(3)
}
if i == self.currSeleIdx{
expandBtn.backgroundColor = HexColor("#D3E4FF")
expandBtn.layer.borderWidth = 0.65
expandBtn.layer.borderColor = HexColor("#478BFF")?.cgColor
expandBtn.isSelected = true
titleLbl.textColor = HexColor("#0668E7")
subTitleLbl.textColor = HexColor("#0668E7")
}else{
expandBtn.backgroundColor = HexColor("#000000")
expandBtn.layer.borderWidth = 0
expandBtn.layer.borderColor = HexColor("#000000")?.cgColor
expandBtn.isSelected = false
titleLbl.textColor = HexColor("#FFFFFF")
subTitleLbl.textColor = HexColor("#FFFFFF")
}
}
}
func resetGaoqing(){
let btnTag:Int = 101
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
for lbl in tmpBtn.subviews{
if let tmpLbl = lbl as? UILabel{
tmpLbl.textColor = HexColor("#0668E7")
}
}
}
}else{
if let tmpBtn = obj as? UIButton{
tmpBtn.backgroundColor = HexColor("#000000")
tmpBtn.layer.borderWidth = 0
tmpBtn.layer.borderColor = HexColor("#000000")?.cgColor
tmpBtn.isSelected = false
for lbl in tmpBtn.subviews{
if let tmpLbl = lbl as? UILabel{
tmpLbl.textColor = HexColor("#FFFFFF")
}
}
}
}
}
}
}
@objc func gaoqingBtnAction(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
for lbl in tmpBtn.subviews{
if let tmpLbl = lbl as? UILabel{
tmpLbl.textColor = HexColor("#0668E7")
}
}
}
}else{
if let tmpBtn = obj as? UIButton{
tmpBtn.backgroundColor = HexColor("#000000")
tmpBtn.layer.borderWidth = 0
tmpBtn.layer.borderColor = HexColor("#000000")?.cgColor
tmpBtn.isSelected = false
for lbl in tmpBtn.subviews{
if let tmpLbl = lbl as? UILabel{
tmpLbl.textColor = HexColor("#FFFFFF")
}
}
}
}
}
}
let i = btn.tag-100
var gaoqing:Int = 3
if i == 0{
gaoqing = 2
}else if i == 1{
gaoqing = 3
}else if i == 2{
gaoqing = 4
}
self.gaoqingUpdateBlock?(gaoqing)
}
@objc func tapAction(){
self.isHidden = true
}
}