Commit 59845980 authored by pete谢兆麟's avatar pete谢兆麟

去除抽屉效果

parent fa1705fd
......@@ -18,23 +18,25 @@ class YHServerHKLifeViewController: YHBaseViewController {
var cell: YHServerHKLifeViewCell!
var dataSouce: [YHHomeListModel?] = [] {
didSet {
cell.tableFootView.items = dataSouce
homeCollectView.reloadData()
}
}
var homeTableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
tableView.backgroundColor = .clear
tableView.separatorStyle = .none
tableView.showsHorizontalScrollIndicator = false
tableView.showsVerticalScrollIndicator = false
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 81.0
tableView.bounces = false
tableView.register(YHServerHKLifeViewCell.self,forCellReuseIdentifier: YHServerHKLifeViewCell.cellReuseIdentifier)
return tableView
lazy var homeCollectView = {
// 设置布局方向
let flowLayout = YHHomeCollectionLayout()
flowLayout.minimumInteritemSpacing = 7.0
flowLayout.minimumColumnSpacing = 7.0
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
let collectinoView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
collectinoView.backgroundColor = .white
collectinoView.register(YHHomeCollectionViewCell.self, forCellWithReuseIdentifier:YHHomeCollectionViewCell.cellReuseIdentifier)
collectinoView.delegate = self
collectinoView.dataSource = self
collectinoView.translatesAutoresizingMaskIntoConstraints = false
collectinoView.alwaysBounceVertical = true
return collectinoView
}()
override func viewDidLoad() {
......@@ -46,6 +48,7 @@ class YHServerHKLifeViewController: YHBaseViewController {
super.viewWillAppear(animated)
loadData()
}
}
extension YHServerHKLifeViewController {
......@@ -70,7 +73,7 @@ extension YHServerHKLifeViewController {
guard let self = self else { return }
self.dataSouce = self.homeViewModel.arrHomeNewsData ?? []
if self.homeViewModel.hasMoreForHomeNews == false {
self.homeTableView.es.noticeNoMoreData()
self.homeCollectView.es.noticeNoMoreData()
}
}
}
......@@ -83,160 +86,114 @@ extension YHServerHKLifeViewController {
gk_navBarAlpha = 0
gk_navigationBar.isHidden = true
view.backgroundColor = .white
sectionView = {
let view = YHServiceSectionView()
view.block = {[weak self] model in
guard let self = self else { return }
self.cell.tableFootView.myCollectView.es.resetNoMoreData()
self.cell.tableFootView.myCollectView.setContentOffset(CGPoint.zero, animated: false)
self.setScrollState()
self.homeCollectView.es.resetNoMoreData()
if homeCollectView.contentOffset.y > -48 {
self.homeCollectView.setContentOffset(CGPoint(x: 0, y: -48), animated: false)
}
self.classId = model.id
self.homeViewModel.getList(true, model.id) {[weak self] success, error in
guard let self = self else { return }
self.dataSouce = self.homeViewModel.arrHomeNewsData ?? []
if self.homeViewModel.hasMoreForHomeNews == false {
self.homeTableView.es.noticeNoMoreData()
self.homeCollectView.es.noticeNoMoreData()
}
}
}
return view
}()
tableHeadView = YHServerTableHeadView()
tableHeadView.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: 365)
view.addSubview(homeTableView)
homeTableView.tableHeaderView = tableHeadView
homeTableView.tableFooterView = tableFootView
homeTableView.snp.makeConstraints { make in
view.addSubview(homeCollectView)
homeCollectView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.bottom.equalToSuperview()
}
homeTableView.delegate = self
homeTableView.dataSource = self
tableHeadView = YHServerTableHeadView()
tableHeadView.titleLabel.text = "香港身份攻略"
tableHeadView.frame = CGRect(x: 0, y: -365 - 48, width: KScreenWidth, height: 365)
sectionView.frame = CGRect(x: 0, y: -48, width: KScreenWidth, height: 48)
homeCollectView.addSubview(tableHeadView)
homeCollectView.addSubview(sectionView)
homeCollectView.contentInset = UIEdgeInsets(top: 365 + 48, left: 0, bottom: 0, right: 0)
homeCollectView.delegate = self
homeCollectView.dataSource = self
homeCollectView.es.addInfiniteScrolling {
self.loadMoreData()
}
}
func setScrollState() {
let offsetY = homeTableView.contentOffset.y
if offsetY >= 365 {
homeTableView.isScrollEnabled = false
cell.tableFootView.myCollectView.isScrollEnabled = true
} else {
homeTableView.isScrollEnabled = true
cell.tableFootView.myCollectView.isScrollEnabled = false
func loadMoreData() {
self.homeViewModel.getList(false, self.classId) {[weak self] success, error in
guard let self = self else { return }
DispatchQueue.main.asyncAfter(wallDeadline: .now() + 0.35, execute: {
CATransaction.setDisableActions(true)
self.dataSouce = self.homeViewModel.arrHomeNewsData ?? []
CATransaction.commit()
self.homeCollectView.es.stopLoadingMore()
if self.homeViewModel.hasMoreForHomeNews == false {
self.homeCollectView.es.noticeNoMoreData()
}
})
}
}
}
// MARK: - UITableViewDelegate 和 UITableViewDataSource
extension YHServerHKLifeViewController : UITableViewDelegate,UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if sectionView.items.count == 1 {
return 0
}
return 48
}
extension YHServerHKLifeViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return sectionView
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.dataSouce.count
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.01
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
// return KScreenHeight - k_Height_NavigationtBarAndStatuBar - 48 - k_Height_safeAreaInsetsBottom() - 50
return self.view.frame.height - 48
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHHomeCollectionViewCell.cellReuseIdentifier, for: indexPath) as! YHHomeCollectionViewCell
cell.listModel = self.dataSouce[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell = tableView.dequeueReusableCell(withClass: YHServerHKLifeViewCell.self)
cell.moreBlock = {[weak self] in
guard let self = self else { return }
self.homeViewModel.getList(false, self.classId) {[weak self] success, error in
guard let self = self else { return }
DispatchQueue.main.asyncAfter(wallDeadline: .now() + 0.35, execute: {
CATransaction.setDisableActions(true)
self.dataSouce = self.homeViewModel.arrHomeNewsData ?? []
CATransaction.commit()
self.cell.tableFootView.myCollectView.es.stopLoadingMore()
if self.homeViewModel.hasMoreForHomeNews == false {
self.cell.tableFootView.myCollectView.es.noticeNoMoreData()
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let model = self.dataSouce[indexPath.row] else { return }
if model.type == 2 {
let vc = YHHomeWebViewController()
vc.url = YHBaseUrlManager.shared.curH5URL() + "articleDetail.html" + "?id=\(model.id)"
vc.id = model.id
vc.block = { item in
let arr = self.dataSouce
for (index,targetItem) in arr.enumerated() {
guard let target = targetItem else { return }
if target.id == item.id {
target.is_like = item.is_like
target.like_count = item.like_count
self.homeCollectView.reloadItems(at: [IndexPath.SubSequence(item: index, section: 0)])
}
})
}
}
self.navigationController?.pushViewController(vc)
} else if model.type == 1 {
printLog("直接播放视频")
}
cell.scrollBlock = { [weak self] falg in
guard let self = self else { return }
tableView.isScrollEnabled = falg
}
cell.tableFootView.items = dataSouce
// cell.tableFootView.myCollectView.es.removeRefreshFooter()
cell.selectionStyle = .none
// cell.tableFootView.myCollectView.isScrollEnabled = false
cell.tableFootView.isNeedScrollBlock = true
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offset = scrollView.contentOffset.y
if offset > -48 {
sectionView.frame.origin.y = offset
} else {
sectionView.frame.origin.y = -48
}
}
}
extension YHServerHKLifeViewController : CollectionViewWaterfallLayoutDelegate {
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
guard let model = self.dataSouce[indexPath.row] else { return CGSize.zero }
return CGSize(width: model.img_width_cell, height: model.img_height_cell)
}
// func scrollViewDidScroll(_ scrollView: UIScrollView) {
// if scrollView == homeTableView {
// let offsetY = homeTableView.contentOffset.y
// if offsetY >= 365 {
// homeTableView.isScrollEnabled = false
// cell.tableFootView.myCollectView.isScrollEnabled = true
// } else {
// homeTableView.isScrollEnabled = true
// cell.tableFootView.myCollectView.isScrollEnabled = false
// }
// }
// }
//
// func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
// // 用户停止拖拽时调用,可以执行一些后续操作
// if scrollView == homeTableView {
// let offsetY = homeTableView.contentOffset.y
// if offsetY >= 365 {
// homeTableView.isScrollEnabled = false
// cell.tableFootView.myCollectView.isScrollEnabled = true
// } else {
// homeTableView.isScrollEnabled = true
// cell.tableFootView.myCollectView.isScrollEnabled = false
// }
// }
// }
//
// func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
// // 滚动减速完成时调用,表示滚动完全停止
// if scrollView == homeTableView {
// let offsetY = homeTableView.contentOffset.y
// if offsetY >= 365 {
// homeTableView.isScrollEnabled = false
// cell.tableFootView.myCollectView.isScrollEnabled = true
// } else {
// homeTableView.isScrollEnabled = true
// cell.tableFootView.myCollectView.isScrollEnabled = false
// }
// }
// }
}
extension YHServerHKLifeViewController: JXSegmentedListContainerViewListDelegate {
......
......@@ -18,23 +18,25 @@ class YHServiceListViewController: YHBaseViewController {
var cell: YHServerHKLifeViewCell!
var dataSouce: [YHHomeListModel?] = [] {
didSet {
cell.tableFootView.items = dataSouce
homeCollectView.reloadData()
}
}
var homeTableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .plain)
if #available(iOS 15.0, *) {
tableView.sectionHeaderTopPadding = 0
}
tableView.backgroundColor = .clear
tableView.separatorStyle = .none
tableView.showsHorizontalScrollIndicator = false
tableView.showsVerticalScrollIndicator = false
tableView.rowHeight = UITableView.automaticDimension
tableView.estimatedRowHeight = 81.0
tableView.bounces = false
tableView.register(YHServerHKLifeViewCell.self,forCellReuseIdentifier: YHServerHKLifeViewCell.cellReuseIdentifier)
return tableView
lazy var homeCollectView = {
// 设置布局方向
let flowLayout = YHHomeCollectionLayout()
flowLayout.minimumInteritemSpacing = 7.0
flowLayout.minimumColumnSpacing = 7.0
flowLayout.sectionInset = UIEdgeInsets(top: 0, left: 20, bottom: 0, right: 20)
let collectinoView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
collectinoView.backgroundColor = .white
collectinoView.register(YHHomeCollectionViewCell.self, forCellWithReuseIdentifier:YHHomeCollectionViewCell.cellReuseIdentifier)
collectinoView.delegate = self
collectinoView.dataSource = self
collectinoView.translatesAutoresizingMaskIntoConstraints = false
collectinoView.alwaysBounceVertical = true
return collectinoView
}()
override func viewDidLoad() {
......@@ -71,7 +73,7 @@ extension YHServiceListViewController {
guard let self = self else { return }
self.dataSouce = self.homeViewModel.arrHomeNewsData ?? []
if self.homeViewModel.hasMoreForHomeNews == false {
self.homeTableView.es.noticeNoMoreData()
self.homeCollectView.es.noticeNoMoreData()
}
}
}
......@@ -88,154 +90,110 @@ extension YHServiceListViewController {
let view = YHServiceSectionView()
view.block = {[weak self] model in
guard let self = self else { return }
self.cell.tableFootView.myCollectView.es.resetNoMoreData()
self.cell.tableFootView.myCollectView.setContentOffset(CGPoint.zero, animated: false)
self.setScrollState()
self.homeCollectView.es.resetNoMoreData()
if homeCollectView.contentOffset.y > -48 {
self.homeCollectView.setContentOffset(CGPoint(x: 0, y: -48), animated: false)
}
self.classId = model.id
self.homeViewModel.getList(true, model.id) {[weak self] success, error in
guard let self = self else { return }
self.dataSouce = self.homeViewModel.arrHomeNewsData ?? []
if self.homeViewModel.hasMoreForHomeNews == false {
self.homeTableView.es.noticeNoMoreData()
self.homeCollectView.es.noticeNoMoreData()
}
}
}
return view
}()
tableHeadView = YHServerTableHeadView()
tableHeadView.titleLabel.text = "香港身份攻略"
tableHeadView.frame = CGRect(x: 0, y: 0, width: KScreenWidth, height: 365)
view.addSubview(homeTableView)
homeTableView.tableHeaderView = tableHeadView
homeTableView.tableFooterView = tableFootView
homeTableView.snp.makeConstraints { make in
view.addSubview(homeCollectView)
homeCollectView.snp.makeConstraints { make in
make.top.left.right.equalToSuperview()
make.bottom.equalToSuperview()
}
homeTableView.delegate = self
homeTableView.dataSource = self
tableHeadView = YHServerTableHeadView()
tableHeadView.titleLabel.text = "香港身份攻略"
tableHeadView.frame = CGRect(x: 0, y: -365 - 48, width: KScreenWidth, height: 365)
sectionView.frame = CGRect(x: 0, y: -48, width: KScreenWidth, height: 48)
homeCollectView.addSubview(tableHeadView)
homeCollectView.addSubview(sectionView)
homeCollectView.contentInset = UIEdgeInsets(top: 365 + 48, left: 0, bottom: 0, right: 0)
homeCollectView.delegate = self
homeCollectView.dataSource = self
homeCollectView.es.addInfiniteScrolling {
self.loadMoreData()
}
}
func setScrollState() {
let offsetY = homeTableView.contentOffset.y
if offsetY >= 365 {
homeTableView.isScrollEnabled = false
cell.tableFootView.myCollectView.isScrollEnabled = true
} else {
homeTableView.isScrollEnabled = true
cell.tableFootView.myCollectView.isScrollEnabled = false
func loadMoreData() {
self.homeViewModel.getList(false, self.classId) {[weak self] success, error in
guard let self = self else { return }
DispatchQueue.main.asyncAfter(wallDeadline: .now() + 0.35, execute: {
CATransaction.setDisableActions(true)
self.dataSouce = self.homeViewModel.arrHomeNewsData ?? []
CATransaction.commit()
self.homeCollectView.es.stopLoadingMore()
if self.homeViewModel.hasMoreForHomeNews == false {
self.homeCollectView.es.noticeNoMoreData()
}
})
}
}
}
// MARK: - UITableViewDelegate 和 UITableViewDataSource
extension YHServiceListViewController : UITableViewDelegate,UITableViewDataSource {
func numberOfSections(in tableView: UITableView) -> Int {
return 1
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
if sectionView.items.count == 1 {
return 0
}
return 48
}
extension YHServiceListViewController: UICollectionViewDelegate, UICollectionViewDataSource {
func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
return sectionView
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
return self.dataSouce.count
}
func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
return 0.01
}
func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
return UIView()
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return self.view.frame.height - 48
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHHomeCollectionViewCell.cellReuseIdentifier, for: indexPath) as! YHHomeCollectionViewCell
cell.listModel = self.dataSouce[indexPath.row]
return cell
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
cell = tableView.dequeueReusableCell(withClass: YHServerHKLifeViewCell.self)
cell.moreBlock = {[weak self] in
guard let self = self else { return }
self.homeViewModel.getList(false, self.classId) {[weak self] success, error in
guard let self = self else { return }
DispatchQueue.main.asyncAfter(wallDeadline: .now() + 0.35, execute: {
CATransaction.setDisableActions(true)
self.dataSouce = self.homeViewModel.arrHomeNewsData ?? []
CATransaction.commit()
self.cell.tableFootView.myCollectView.es.stopLoadingMore()
if self.homeViewModel.hasMoreForHomeNews == false {
self.cell.tableFootView.myCollectView.es.noticeNoMoreData()
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
guard let model = self.dataSouce[indexPath.row] else { return }
if model.type == 2 {
let vc = YHHomeWebViewController()
vc.url = YHBaseUrlManager.shared.curH5URL() + "articleDetail.html" + "?id=\(model.id)"
vc.id = model.id
vc.block = { item in
let arr = self.dataSouce
for (index,targetItem) in arr.enumerated() {
guard let target = targetItem else { return }
if target.id == item.id {
target.is_like = item.is_like
target.like_count = item.like_count
self.homeCollectView.reloadItems(at: [IndexPath.SubSequence(item: index, section: 0)])
}
})
}
}
self.navigationController?.pushViewController(vc)
} else if model.type == 1 {
printLog("直接播放视频")
}
cell.scrollBlock = { [weak self] falg in
guard let self = self else { return }
tableView.isScrollEnabled = falg
}
cell.tableFootView.items = dataSouce
cell.selectionStyle = .none
// cell.tableFootView.myCollectView.isScrollEnabled = false
cell.tableFootView.isNeedScrollBlock = true
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let offset = scrollView.contentOffset.y
if offset > -48 {
sectionView.frame.origin.y = offset
} else {
sectionView.frame.origin.y = -48
}
}
}
extension YHServiceListViewController : CollectionViewWaterfallLayoutDelegate {
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
guard let model = self.dataSouce[indexPath.row] else { return CGSize.zero }
return CGSize(width: model.img_width_cell, height: model.img_height_cell)
}
// func scrollViewDidScroll(_ scrollView: UIScrollView) {
// if scrollView == homeTableView {
// let offsetY = homeTableView.contentOffset.y
// if offsetY >= 365 {
// homeTableView.isScrollEnabled = false
// cell.tableFootView.myCollectView.isScrollEnabled = true
// } else {
// homeTableView.isScrollEnabled = true
// cell.tableFootView.myCollectView.isScrollEnabled = false
// }
// }
// }
//
// func scrollViewDidEndDragging(_ scrollView: UIScrollView, willDecelerate decelerate: Bool) {
// // 用户停止拖拽时调用,可以执行一些后续操作
// if scrollView == homeTableView {
// let offsetY = homeTableView.contentOffset.y
// if offsetY >= 365 {
// homeTableView.isScrollEnabled = false
// cell.tableFootView.myCollectView.isScrollEnabled = true
// } else {
// homeTableView.isScrollEnabled = true
// cell.tableFootView.myCollectView.isScrollEnabled = false
// }
// }
// }
//
// func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
// // 滚动减速完成时调用,表示滚动完全停止
// if scrollView == homeTableView {
// let offsetY = homeTableView.contentOffset.y
// if offsetY >= 365 {
// homeTableView.isScrollEnabled = false
// cell.tableFootView.myCollectView.isScrollEnabled = true
// } else {
// homeTableView.isScrollEnabled = true
// cell.tableFootView.myCollectView.isScrollEnabled = false
// }
// }
// }
}
extension YHServiceListViewController: JXSegmentedListContainerViewListDelegate {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment