CNUpSlideViewController.swift
3.51 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
//
// CNUpSlideViewController.swift
// metaCode
//
// Created by zx on 2023/10/13.
//
import Foundation
import UIKit
class CNUpSlideViewController: CNLiveBaseViewController,UITableViewDelegate,UITableViewDataSource{//UITableViewController {
let kCNLiveDownSlideCellIdentifier = "kCNLiveDownSlideCellIdentifier"
var selectedCell: CNDownSlideCell?
var statusBarShouldBeHidden = false
//we need to set `View controller-based status bar appearance = YES` in info.plist.
//so we can be able to hide statusBar.
override var prefersStatusBarHidden: Bool {
return statusBarShouldBeHidden
}
override var preferredStatusBarUpdateAnimation: UIStatusBarAnimation {
return .slide
}
override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) {
print("slidetouchesBegan")
}
override func viewDidLoad() {
super.viewDidLoad()
view.addSubview(tableView)
tableView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
}
lazy var tableView : UITableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.dataSource = self
tableView.delegate = self
tableView.separatorStyle = .none
tableView.register(CNDownSlideCell.self, forCellReuseIdentifier: kCNLiveDownSlideCellIdentifier)
tableView.rowHeight = GlobalConstants.toDayCardRowH
return tableView
}()
private func updateStatusBarAndTabbarFrame(visible: Bool) {
statusBarShouldBeHidden = !visible
UIView.animate(withDuration: 0.25) {
self.setNeedsStatusBarAppearanceUpdate()
}
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 2
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: kCNLiveDownSlideCellIdentifier) as! CNDownSlideCell
cell.selectionStyle = .none
cell.bgImageView.backgroundColor = .red
cell.bgImageView.kf.setImage(with: URL(string: "https://wjj.ys2.cnliveimg.com/769/img_new/1697162534497.jpg"))
return cell
}
func tableView(_ tableView: UITableView, didHighlightRowAt indexPath: IndexPath) {
guard let row = tableView.cellForRow(at: indexPath) as? CNDownSlideCell else { return }
UIView.animate(withDuration: 0.1) {
row.bgBackView.transform = CGAffineTransform(scaleX: 0.95, y: 0.95)
}
}
func tableView(_ tableView: UITableView, didUnhighlightRowAt indexPath: IndexPath) {
guard let row = tableView.cellForRow(at: indexPath) as? CNDownSlideCell else { return }
UIView.animate(withDuration: 0.3) {
row.bgBackView.transform = CGAffineTransform(scaleX: 1.0, y: 1.0)
}
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
print("点击了cell")
guard let cell = tableView.cellForRow(at: indexPath) as? CNDownSlideCell else { return }
selectedCell = cell
let detailVC = CNUpSlideDetailViewController(cell: cell)
detailVC.dismissClosure = { [weak self] in
guard let StrongSelf = self else { return }
StrongSelf.updateStatusBarAndTabbarFrame(visible: true)
}
updateStatusBarAndTabbarFrame(visible: false)
present(detailVC, animated: true, completion: nil)
}
}