fix
杨锴
2024-08-23 adc2db9bb29e7f316c46b6de679db1522ffc9cc8
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
//
//  HomeVC.swift
//  XQMuse
//
//  Created by 无故事王国 on 2024/8/12.
//
 
import UIKit
import JQTools
import MediaPlayer
 
struct TitleItem{
                var title = ""
                var subTitle = ""
                var hasMore:Bool = false
                var coverImage:String?
}
 
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))
                                titleItems.append(TitleItem(title: "放松助眠", subTitle: "与内心的宁静与喜悦入睡",hasMore:true))
 
                                let vc = LoginTreatyVC()
                                vc.modalPresentationStyle = .custom
                                present(vc, animated: 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.contentInset = UIEdgeInsets(top: 0, left: 0, bottom: 40, right: 0)
                                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)
                }
 
                @objc func jumpMoreAction(_ sender:UIButton){
                                switch sender.tag {
                                                case 201:
                                                                //跳转计划引导
                                                                break
                                                default:
                                                                 let topTitle = titleItems[sender.tag - 200].title
                                                                let vc = HomeItemListVC(topTitle: topTitle, id: 0)
                                                                push(vc: vc)
                                }
                }
 
}
 
extension HomeVC:UITableViewDelegate & UITableViewDataSource{
 
                func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
                                if indexPath.section == 2{
                                                let vc = HomeTyroGuideVC()
                                                push(vc: vc)
                                }
                }
 
                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_4_TCell") as! Home_Style_4_TCell
                                                cell.style = .style1
                                                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
                                                cell.style = .style2
                                                return cell
                                }
 
                                if indexPath.section == 5{
                                                let cell = tableView.dequeueReusableCell(withIdentifier: "_Home_Style_4_TCell") as! Home_Style_4_TCell
                                                cell.style = .style2
                                                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
                                headerView.btn_more.tag = section + 200
                                headerView.btn_more.addTarget(self, action: #selector(jumpMoreAction(_:)), for: .touchUpInside)
 
                                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
                }
 
 
}
 
extension HomeVC:UIScrollViewDelegate{
                func scrollViewDidScroll(_ scrollView: UIScrollView) {
                                let v = min(scrollView.contentOffset.y / JQ_NavBarHeight, 1)
                                navigationController?.navigationBar.standardAppearance.backgroundColor = .white.withAlphaComponent(v)
                }
}