Commit f301fa55 authored by Steven杜宇's avatar Steven杜宇

// plan

parent d29e230c
...@@ -17,6 +17,7 @@ class YHPlanPolicyImageInfo { ...@@ -17,6 +17,7 @@ class YHPlanPolicyImageInfo {
class YHPlanPolicyDetailViewController: YHBaseViewController { class YHPlanPolicyDetailViewController: YHBaseViewController {
var firstAppear: Bool = true
var arr: [YHPlanCaseModel] = [] { var arr: [YHPlanCaseModel] = [] {
didSet { didSet {
imgs.removeAll() imgs.removeAll()
...@@ -25,6 +26,7 @@ class YHPlanPolicyDetailViewController: YHBaseViewController { ...@@ -25,6 +26,7 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
model.model = item model.model = item
imgs.append(model) imgs.append(model)
} }
self.collectionView.reloadData()
} }
} }
...@@ -32,17 +34,18 @@ class YHPlanPolicyDetailViewController: YHBaseViewController { ...@@ -32,17 +34,18 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
var imgs: [YHPlanPolicyImageInfo] = [] var imgs: [YHPlanPolicyImageInfo] = []
// lazy var scrollView: UIScrollView = { lazy var bgImgView: UIImageView = {
// let v = UIScrollView(frame: .zero) let v = UIImageView()
// return v v.clipsToBounds = true
// }() return v
}()
lazy var collectionView: UICollectionView = { lazy var collectionView: UICollectionView = {
let layout = UICollectionViewFlowLayout() let layout = UICollectionViewFlowLayout()
layout.minimumInteritemSpacing = 0.0 layout.minimumInteritemSpacing = 0.0
layout.minimumLineSpacing = 0.0 layout.minimumLineSpacing = 0.0
layout.scrollDirection = .horizontal layout.scrollDirection = .horizontal
let collectView = UICollectionView(frame: .zero, collectionViewLayout: layout) let collectView = UICollectionView(frame: CGRect(x: 0, y: k_Height_NavigationtBarAndStatuBar+24.0, width: KScreenWidth, height: 520), collectionViewLayout: layout)
collectView.backgroundColor = .clear collectView.backgroundColor = .clear
collectView.delegate = self collectView.delegate = self
collectView.dataSource = self collectView.dataSource = self
...@@ -51,6 +54,12 @@ class YHPlanPolicyDetailViewController: YHBaseViewController { ...@@ -51,6 +54,12 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
return collectView return collectView
}() }()
lazy var blurView: UIVisualEffectView = {
let blurEffect = UIBlurEffect(style: .light) // 可以选择不同的模糊样式
let blurEffectView = UIVisualEffectView(effect: blurEffect)
return blurEffectView
}()
lazy var shareBtn: UIButton = { lazy var shareBtn: UIButton = {
let btn = UIButton() let btn = UIButton()
btn.backgroundColor = .white btn.backgroundColor = .white
...@@ -69,9 +78,18 @@ class YHPlanPolicyDetailViewController: YHBaseViewController { ...@@ -69,9 +78,18 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
gk_navTitle = "\(currentIndex+1)/\(arr.count)" gk_navTitle = "\(currentIndex+1)/\(arr.count)"
gk_navTitleColor = .white gk_navTitleColor = .white
view.backgroundColor = .init(hex: 0x000000, alpha: 1.0) view.backgroundColor = .init(hex: 0x000000, alpha: 1.0)
view.addSubview(bgImgView)
view.addSubview(blurView)
view.addSubview(collectionView) view.addSubview(collectionView)
view.addSubview(shareBtn) view.addSubview(shareBtn)
bgImgView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
blurView.snp.makeConstraints { make in
make.edges.equalToSuperview()
}
collectionView.snp.makeConstraints { make in collectionView.snp.makeConstraints { make in
make.left.right.equalToSuperview() make.left.right.equalToSuperview()
make.top.equalTo(k_Height_NavigationtBarAndStatuBar+24.0) make.top.equalTo(k_Height_NavigationtBarAndStatuBar+24.0)
...@@ -84,8 +102,26 @@ class YHPlanPolicyDetailViewController: YHBaseViewController { ...@@ -84,8 +102,26 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
make.height.equalTo(46) make.height.equalTo(46)
make.top.equalTo(collectionView.snp.bottom).offset(32) make.top.equalTo(collectionView.snp.bottom).offset(32)
} }
collectionView.setContentOffset(CGPoint(x: KScreenWidth * Double(currentIndex), y: 0.0), animated: true)
loadImgs() loadImgs()
showBgImage(index: currentIndex)
}
func showBgImage(index: Int) {
if 0 <= index, index < arr.count {
let model = arr[index]
if let url = URL(string: model.img_url) {
bgImgView.kf.setImage(with: url)
}
}
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
if firstAppear {
collectionView.scrollToItem(at: IndexPath(row: currentIndex, section: 0), at: .top, animated: false)
firstAppear = false
}
} }
func loadImgs() { func loadImgs() {
...@@ -123,7 +159,7 @@ extension YHPlanPolicyDetailViewController: UICollectionViewDelegate, UICollecti ...@@ -123,7 +159,7 @@ extension YHPlanPolicyDetailViewController: UICollectionViewDelegate, UICollecti
// 返回每个单元格的大小 // 返回每个单元格的大小
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize { func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
return CGSize(width: KScreenWidth, height: collectionView.height) return CGSize(width: KScreenWidth, height: 520)
} }
// 返回自定义单元格 // 返回自定义单元格
...@@ -150,6 +186,7 @@ extension YHPlanPolicyDetailViewController: UIScrollViewDelegate { ...@@ -150,6 +186,7 @@ extension YHPlanPolicyDetailViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) { func scrollViewDidScroll(_ scrollView: UIScrollView) {
let currentIndex = Int(scrollView.contentOffset.x/KScreenWidth) let currentIndex = Int(scrollView.contentOffset.x/KScreenWidth)
gk_navTitle = "\(currentIndex+1)/\(arr.count)" gk_navTitle = "\(currentIndex+1)/\(arr.count)"
showBgImage(index: currentIndex)
} }
} }
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