-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathCLStackViewController.swift
More file actions
159 lines (134 loc) · 4.49 KB
/
CLStackViewController.swift
File metadata and controls
159 lines (134 loc) · 4.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
//
// CLStackViewController.swift
// CLPlayer
//
// Created by Chen JmoVxia on 2021/12/14.
//
import SnapKit
import UIKit
class CLStackViewController: CLController {
override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
super.init(nibName: nibNameOrNil, bundle: nibBundleOrNil)
}
@available(*, unavailable)
required init?(coder _: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
private lazy var placeholderView: CLPlaceholderView = {
let view = CLPlaceholderView()
view.addTarget(self, action: #selector(playAction), for: .touchUpInside)
return view
}()
private lazy var player: CLPlayer = {
let view = CLPlayer()
view.placeholder = placeholderView
return view
}()
private lazy var changeButton: UIButton = {
let view = UIButton()
view.backgroundColor = UIColor.orange.withAlphaComponent(0.3)
view.titleLabel?.font = .systemFont(ofSize: 18)
view.setTitle("切换视频", for: .normal)
view.setTitle("切换视频", for: .selected)
view.setTitle("切换视频", for: .highlighted)
view.setTitleColor(.orange, for: .normal)
view.setTitleColor(.orange, for: .selected)
view.setTitleColor(.orange, for: .highlighted)
view.addTarget(self, action: #selector(changeAction), for: .touchUpInside)
return view
}()
private lazy var mainStackView: UIStackView = {
let view = UIStackView()
view.axis = .vertical
view.distribution = .fill
view.alignment = .fill
view.insetsLayoutMarginsFromSafeArea = false
view.isLayoutMarginsRelativeArrangement = true
view.layoutMargins = .zero
view.spacing = 40
return view
}()
deinit {
print("CLStackViewController deinit")
}
}
// MARK: - JmoVxia---生命周期
extension CLStackViewController {
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
}
override func viewDidLoad() {
super.viewDidLoad()
initUI()
makeConstraints()
initData()
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
}
override func viewDidDisappear(_ animated: Bool) {
super.viewDidDisappear(animated)
}
override func viewDidLayoutSubviews() {
super.viewDidLayoutSubviews()
}
}
// MARK: - JmoVxia---布局
private extension CLStackViewController {
func initUI() {
updateTitleLabel { $0.text = "UIView" }
view.addSubview(mainStackView)
mainStackView.addArrangedSubview(player)
mainStackView.addArrangedSubview(changeButton)
}
func makeConstraints() {
mainStackView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.center.equalToSuperview()
make.height.equalTo(view.bounds.width / (16.0 / 9.0) + 50)
}
changeButton.snp.makeConstraints { make in
make.height.equalTo(50)
}
}
}
// MARK: - JmoVxia---数据
private extension CLStackViewController {
func initData() {
player.title = NSMutableAttributedString("Apple", attributes: { $0
.font(.systemFont(ofSize: 16))
.foregroundColor(.white)
.alignment(.center)
})
}
}
extension CLStackViewController {
override var shouldAutorotate: Bool {
return false
}
// 支持哪些屏幕方向
override var supportedInterfaceOrientations: UIInterfaceOrientationMask {
return .portrait
}
}
// MARK: - JmoVxia---objc
@objc private extension CLStackViewController {
func playAction() {
placeholderView.imageView.image = UIImage(named: "placeholder")
player.url = URL(string: "https://www.apple.com/105/media/cn/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/bruce/mac-bruce-tpl-cn-2018_1280x720h.mp4")
player.play()
}
func changeAction() {
placeholderView.imageView.image = UIImage(named: "placeholder1")
player.title = NSMutableAttributedString("这是一个标题", attributes: { $0
.font(.systemFont(ofSize: 16))
.foregroundColor(.white)
.alignment(.left)
})
player.url = URL(string: "http://vjs.zencdn.net/v/oceans.mp4")
player.play()
}
}