杨锴
2024-08-14 909e20941e45f8712c012db602034b47da0bfdb0
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
//
//  HomeVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/12.
//
 
import UIKit
import JQTools
 
struct TitleItem{
                var title = ""
                var subTitle = ""
                var hasMore:Bool = false
}
 
class HomeVC: BaseVC {
                private var tableView:UITableView!
                private let topMenuView = HomeTopMenuView.jq_loadNibView()
                private var titleItems = [TitleItem]()
 
    override func viewDidLoad() {
        super.viewDidLoad()
 
                                titleItems.append(TitleItem(title: "每日疗愈", subTitle: "Daily Meditation"))
                                titleItems.append(TitleItem(title: "私人订制", subTitle: "Private Meditation",hasMore: true))
                                titleItems.append(TitleItem(title: "新手冥想指南", subTitle: "Meditation guide"))
                                titleItems.append(TitleItem(title: "放松助眠", subTitle: "与内心的宁静与喜悦入睡",hasMore:true))
                                titleItems.append(TitleItem(title: "放松助眠", subTitle: "与内心的宁静与喜悦入睡",hasMore:true))
 
    }
 
                override func setUI() {
                                super.setUI()
 
                                let titleView = UIView()
                                titleView.frame = CGRect(x: 0, y: 0, width: 100, height: 40)
                                let titleL = UILabel()
                                titleL.font = Def_SourceHanSansCN_Regular(fontSize: 21)
                                titleL.text = "心 泉 疗 愈"
                                titleL.textAlignment = .center
                                titleL.textColor = UIColor(hexStr: "#252A23")
                                titleL.frame = CGRect(x: 0, y: 0, width: 100, height: 19)
 
                                let subTitleL = UILabel()
                                subTitleL.font = Def_Agenda_Light(fontSize: 8)
                                subTitleL.text = "XIN QUAN"
                                subTitleL.textAlignment = .center
                                subTitleL.textColor = UIColor(hexStr: "#252A23")
                                subTitleL.frame = CGRect(x: 0, y: 20, width: 100, height: 19)
 
 
                                titleView.addSubview(titleL)
                                titleView.addSubview(subTitleL)
 
 
                                navigationItem.titleView = titleView
 
                                 let search = UIButton(type: .custom)
                                search.setImage(UIImage(named: "btn_search"), for: .normal)
                                search.addTarget(self, action: #selector(searchAction), for: .touchUpInside)
                                search.bounds = CGRect(origin: .zero, size:CGSize(width: 50, height: 30))
                                navigationItem.leftBarButtonItem = UIBarButtonItem(customView: search)
 
 
                                let voices = UIButton(type: .custom)
                                voices.setImage(UIImage(named: "btn_voices"), for: .normal)
                                voices.addTarget(self, action: #selector(settingvoiceAction), for: .touchUpInside)
                                voices.bounds = CGRect(origin: .zero, size:CGSize(width: 50, height: 30))
                                navigationItem.rightBarButtonItem = UIBarButtonItem(customView: voices)
 
                                tableView = UITableView(frame: .zero, style: .plain)
                                tableView.showsVerticalScrollIndicator = false
                                DispatchQueue.main.async {
                                                let height = self.topMenuView.systemLayoutSizeFitting(UIView.layoutFittingCompressedSize).height
                                                self.topMenuView.frame = CGRect(x: 0, y: 0, width: JQ_ScreenW, height: height - 70)
                                                self.tableView.tableHeaderView = self.topMenuView
                                }
 
                                tableView.tableHeaderView = topMenuView
 
                                tableView.register(UINib(nibName: "Home_Style_1_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_1_TCell")
                                tableView.register(UINib(nibName: "Home_Style_2_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_2_TCell")
                                tableView.register(UINib(nibName: "Home_Style_3_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_3_TCell")
                                tableView.register(UINib(nibName: "Home_Style_4_TCell", bundle: nil), forCellReuseIdentifier: "_Home_Style_4_TCell")
 
                                tableView.separatorStyle = .none
                                tableView.delegate = self
                                tableView.dataSource = self
                                if #available(iOS 15.0, *) {
                                                tableView.sectionHeaderTopPadding = 0
                                } else {
 
                                }
                                tableView.register(HomeHeaderView.self, forHeaderFooterViewReuseIdentifier: "_HomeHeaderView")
                                view.addSubview(tableView)
                                tableView.snp.makeConstraints { make in
                                                make.edges.equalToSuperview()
                                }
                }
 
                override func setRx() {
                                topMenuView.clickItemAt {[unowned self] item in
                                                let vc = HomeItemListVC(topTitle: item.title, id: item.id)
                                                self.push(vc: vc)
                                }
                }
 
                @objc func searchAction(){
                                let vc = SearchVC()
                                push(vc: vc)
                }
 
                @objc func settingvoiceAction(){
                                let vc = BackgroundVoiceVC()
                                push(vc: vc)
 
//                                 let nav = LoginNav(rootViewController: LoginVC())
//                                nav.modalPresentationStyle = .fullScreen
//                                present(nav, animated: true)
                }
 
}
 
extension HomeVC:UITableViewDelegate & UITableViewDataSource{
                func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
                                if indexPath.section == 0{
                                                let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_1_TCell") as! Home_Style_1_TCell
                                                return cell
                                }
 
                                if indexPath.section == 1{
                                                let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_2_TCell") as! Home_Style_2_TCell
                                                return cell
                                }
 
                                if indexPath.section == 2{
                                                let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_2_TCell") as! Home_Style_2_TCell
                                                cell.view_shadow.isHidden = true
                                                return cell
                                }
 
                                if indexPath.section == 3{
                                                let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_3_TCell") as! Home_Style_3_TCell
                                                return cell
                                }
 
                                if indexPath.section == 4{
                                                let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_4_TCell") as! Home_Style_4_TCell
                                                return cell
                                }
 
                                if indexPath.section == 5{
                                                let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_4_TCell") as! Home_Style_4_TCell
                                                return cell
                                }
 
                                return UITableViewCell()
                }
 
                func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
                                return 1
                }
 
                func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
                                if indexPath.section == 0 || indexPath.section == 1 || indexPath.section == 2{
                                                return JQ_ScreenW * 0.551
                                }
                                if indexPath.section == 3{
                                                return 397.3
                                }
                                if indexPath.section == 4 || indexPath.section == 5{
                                                return 328
                                }
                                return 0
                }
 
                func numberOfSections(in tableView: UITableView) -> Int {
                                return titleItems.count
                }
 
                func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
                                return 80.5
                }
 
                func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
                                let headerView = tableView.dequeueReusableHeaderFooterView(withIdentifier: "_HomeHeaderView") as! HomeHeaderView
                                headerView.setTitle(titleItems[section].title, subTitle: titleItems[section].subTitle)
                                headerView.btn_more.isHidden = !titleItems[section].hasMore
 
                                if section == 1{
                                                headerView.btn_more.setImage(UIImage(named: "btn_more"), for: .normal)
                                }else{
                                                headerView.btn_more.setImage(UIImage(named: "icon_exchange"), for: .normal)
                                }
 
                                return headerView
                }
 
 
}