Commit 25b0487d authored by pete谢兆麟's avatar pete谢兆麟

无状态UI

parent acbc09fd
...@@ -32,6 +32,7 @@ class YHLifeViewController: YHBaseViewController { ...@@ -32,6 +32,7 @@ class YHLifeViewController: YHBaseViewController {
collectinoView.backgroundColor = .white collectinoView.backgroundColor = .white
// collectinoView.contentInset = UIEdgeInsets(top: 16, left: 20, bottom: 0, right: 20) // collectinoView.contentInset = UIEdgeInsets(top: 16, left: 20, bottom: 0, right: 20)
collectinoView.register(YHLookCollectionViewCell.self, forCellWithReuseIdentifier:YHLookCollectionViewCell.cellReuseIdentifier) collectinoView.register(YHLookCollectionViewCell.self, forCellWithReuseIdentifier:YHLookCollectionViewCell.cellReuseIdentifier)
collectinoView.register(YHLookNodataCollectionViewCell.self, forCellWithReuseIdentifier:YHLookNodataCollectionViewCell.cellReuseIdentifier)
collectinoView.register(YHlifeCollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: YHlifeCollectionReusableView.reuseIdentifier) collectinoView.register(YHlifeCollectionReusableView.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionFooter, withReuseIdentifier: YHlifeCollectionReusableView.reuseIdentifier)
collectinoView.delegate = self collectinoView.delegate = self
collectinoView.dataSource = self collectinoView.dataSource = self
...@@ -42,12 +43,6 @@ class YHLifeViewController: YHBaseViewController { ...@@ -42,12 +43,6 @@ class YHLifeViewController: YHBaseViewController {
return collectinoView return collectinoView
}() }()
lazy var noDataView: YHEmptyDataView = {
let view = YHEmptyDataView.createView("暂无直播", kEmptyCommonBgName)
view.isHidden = true
return view
}()
override func viewDidLoad() { override func viewDidLoad() {
super.viewDidLoad() super.viewDidLoad()
...@@ -89,13 +84,6 @@ extension YHLifeViewController { ...@@ -89,13 +84,6 @@ extension YHLifeViewController {
self.viewModel.getLiveList {[weak self] success, error in self.viewModel.getLiveList {[weak self] success, error in
guard let self = self else { return } guard let self = self else { return }
self.myCollectView.reloadData() self.myCollectView.reloadData()
if hideFlag {
if self.viewModel.liveArr.count == 0 {
noDataView.isHidden = false
} else {
noDataView.isHidden = true
}
}
} }
self.viewModel.getSchedulLiveList {[weak self] success, error in self.viewModel.getSchedulLiveList {[weak self] success, error in
...@@ -200,21 +188,12 @@ extension YHLifeViewController { ...@@ -200,21 +188,12 @@ extension YHLifeViewController {
make.right.equalToSuperview().offset(-20) make.right.equalToSuperview().offset(-20)
} }
view.addSubview(noDataView)
noDataView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
make.width.equalTo(KScreenWidth)
make.height.equalTo(150)
}
myCollectView.es.addYHPullToRefresh { myCollectView.es.addYHPullToRefresh {
self.loadData() self.loadData()
self.myCollectView.es.stopPullToRefresh() self.myCollectView.es.stopPullToRefresh()
} }
myCollectView.isHidden = !hideFlag myCollectView.isHidden = !hideFlag
noDataView.isHidden = !hideFlag
} }
func checkLogin()->Bool { func checkLogin()->Bool {
...@@ -280,10 +259,17 @@ extension YHLifeViewController: JXSegmentedListContainerViewListDelegate { ...@@ -280,10 +259,17 @@ extension YHLifeViewController: JXSegmentedListContainerViewListDelegate {
extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout { extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSource, UICollectionViewDelegateFlowLayout {
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int { func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
if self.viewModel.liveArr.count == 0 {
return 1
}
return self.viewModel.liveArr.count return self.viewModel.liveArr.count
} }
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell { func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
if self.viewModel.liveArr.count == 0 {
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHLookNodataCollectionViewCell.cellReuseIdentifier, for: indexPath) as! YHLookNodataCollectionViewCell
return cell
}
let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHLookCollectionViewCell.cellReuseIdentifier, for: indexPath) as! YHLookCollectionViewCell let cell = collectionView.dequeueReusableCell(withReuseIdentifier: YHLookCollectionViewCell.cellReuseIdentifier, for: indexPath) as! YHLookCollectionViewCell
cell.dataSource = self.viewModel.liveArr[indexPath.row] cell.dataSource = self.viewModel.liveArr[indexPath.row]
...@@ -321,6 +307,13 @@ extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSo ...@@ -321,6 +307,13 @@ extension YHLifeViewController: UICollectionViewDelegate, UICollectionViewDataSo
} }
return CGSize(width: KScreenWidth, height: 0) // 根据需要设置高度 return CGSize(width: KScreenWidth, height: 0) // 根据需要设置高度
} }
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
if self.viewModel.liveArr.count == 0 {
return CGSize(width: KScreenWidth - 40, height: 250)
}
return CGSize(width: (KScreenWidth - 52)/2, height: 222)
}
} }
class YHLookCollectionViewCell: UICollectionViewCell { class YHLookCollectionViewCell: UICollectionViewCell {
...@@ -425,3 +418,34 @@ class YHLookCollectionViewCell: UICollectionViewCell { ...@@ -425,3 +418,34 @@ class YHLookCollectionViewCell: UICollectionViewCell {
} }
} }
class YHLookNodataCollectionViewCell: UICollectionViewCell {
static let cellReuseIdentifier = "YHLookNodataCollectionViewCell"
lazy var noDataView: YHEmptyDataView = {
let view = YHEmptyDataView.createView("暂无直播", kEmptyCommonBgName)
return view
}()
required init?(coder: NSCoder) {
super.init(coder: coder)
}
override init(frame: CGRect) {
super.init(frame: frame)
setupUI()
}
private func setupUI() {
contentView.addSubview(noDataView)
noDataView.snp.makeConstraints { make in
make.centerX.equalToSuperview()
make.centerY.equalToSuperview()
make.width.equalToSuperview()
make.height.equalTo(150)
}
}
}
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