CNLiveVodLandscapeBeiSuView.swift
4.43 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
//
// CNLiveVodLandscapeBeiSuView.swift
// metaCode
//
// Created by zx on 2025/3/27.
// 横屏倍速
import Foundation
typealias CNLiveVodLandscapeBeiSuUpdateBlock = (_ rate:Float)->Void
class CNLiveVodLandscapeBeiSuView:UIView{
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)
}
}
@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
}
}