Commit 8e2b46ff authored by Steven杜宇's avatar Steven杜宇

// 方案

parent 2face72e
......@@ -9,7 +9,7 @@
import UIKit
class YHPlanPolicyImageInfo {
var url: String = ""
var model: YHPlanCaseModel = YHPlanCaseModel()
var imgView: UIImageView = UIImageView()
let height: CGFloat = 520.0
var width: CGFloat = 520.0
......@@ -17,17 +17,19 @@ class YHPlanPolicyImageInfo {
class YHPlanPolicyDetailViewController: YHBaseViewController {
var urls: [String] = [] {
var arr: [YHPlanCaseModel] = [] {
didSet {
imgs.removeAll()
for url in urls {
for item in arr {
let model = YHPlanPolicyImageInfo()
model.url = url
model.model = item
imgs.append(model)
}
}
}
var currentIndex: Int = 0
var imgs: [YHPlanPolicyImageInfo] = []
// lazy var scrollView: UIScrollView = {
......@@ -64,7 +66,7 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
super.viewDidLoad()
gk_backImage = UIImage(named: "nav_back_white")
gk_navTitle = "1/\(urls.count)"
gk_navTitle = "\(currentIndex+1)/\(arr.count)"
gk_navTitleColor = .white
view.backgroundColor = .init(hex: 0x000000, alpha: 1.0)
view.addSubview(collectionView)
......@@ -82,10 +84,7 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
make.height.equalTo(46)
make.top.equalTo(collectionView.snp.bottom).offset(32)
}
urls = ["https://img0.baidu.com/it/u=10464961,1462197942&fm=253&fmt=auto&app=138&f=JPEG?w=500&h=667",
"https://pic1.zhimg.com/v2-66b17db60d1c7c66096eaed9fe2bdb28_r.jpg",
"https://pics3.baidu.com/feed/2cf5e0fe9925bc3174f9833affbb97bcca137059.jpeg@f_auto?token=566818d4692ffdcc23b25f6391dbd061"
]
collectionView.setContentOffset(CGPoint(x: KScreenWidth * Double(currentIndex), y: 0.0), animated: true)
loadImgs()
}
......@@ -93,7 +92,7 @@ class YHPlanPolicyDetailViewController: YHBaseViewController {
let ossGroup = DispatchGroup()
for item in imgs {
ossGroup.enter()
item.imgView.kf.setImage(with: URL(string: item.url)) { result in
item.imgView.kf.setImage(with: URL(string: item.model.img_url)) { result in
switch result {
case let .success(value):
let size = value.image.size
......@@ -150,7 +149,7 @@ extension YHPlanPolicyDetailViewController: UIScrollViewDelegate {
func scrollViewDidScroll(_ scrollView: UIScrollView) {
let currentIndex = Int(scrollView.contentOffset.x/KScreenWidth)
gk_navTitle = "\(currentIndex+1)/\(urls.count)"
gk_navTitle = "\(currentIndex+1)/\(arr.count)"
}
}
......@@ -48,6 +48,27 @@ class YHPlanViewController: YHBaseViewController {
return tableView
}()
lazy var fakeTableView: UITableView = {
let tableView = UITableView(frame: .zero, style: .grouped)
tableView.isHidden = true
if #available(iOS 11.0, *) {
tableView.contentInsetAdjustmentBehavior = .never
}
tableView.showsVerticalScrollIndicator = false
tableView.estimatedSectionHeaderHeight = 1.0
tableView.estimatedSectionFooterHeight = 1.0
tableView.backgroundColor = .clear
tableView.separatorStyle = .none
tableView.delegate = self
tableView.dataSource = self
tableView.register(YHPlanAnalyzeInfoCell.self, forCellReuseIdentifier: YHPlanAnalyzeInfoCell.cellReuseIdentifier)
tableView.register(YHPlanScoreCell.self, forCellReuseIdentifier: YHPlanScoreCell.cellReuseIdentifier)
tableView.register(YHPlanCustomerCaseListCell.self, forCellReuseIdentifier: YHPlanCustomerCaseListCell.cellReuseIdentifier)
tableView.register(UITableViewCell.self, forCellReuseIdentifier: "UITableViewCell")
return tableView
}()
lazy var whiteBackBtn: UIButton = {
let v = UIButton()
v.setImage(UIImage(named: "nav_back_white"), for: .normal)
......@@ -63,8 +84,7 @@ class YHPlanViewController: YHBaseViewController {
}()
@objc func didShareBtnClicked() {
// let vc = YHPlanShareViewController()
let vc = YHPlanPolicyDetailViewController()
let vc = YHPlanShareViewController()
self.navigationController?.pushViewController(vc)
}
......@@ -249,6 +269,14 @@ class YHPlanViewController: YHBaseViewController {
lazy var policyVieiw: YHPlanPolicyCarouselView = {
let v = YHPlanPolicyCarouselView(frame: CGRect(x: 0, y: 0, width: KScreenWidth, height: 268))
v.clickBlock = {
[weak self] arr, index in
guard let self = self else { return }
let vc = YHPlanPolicyDetailViewController()
vc.arr = arr
vc.currentIndex = index
self.navigationController?.pushViewController(vc, animated: true)
}
return v
}()
......@@ -267,6 +295,7 @@ class YHPlanViewController: YHBaseViewController {
self.view.backgroundColor = .init(hex: 0xF8F9FB)
self.view.addSubview(bgImgView)
self.view.addSubview(fakeTableView)
self.view.addSubview(tableView)
self.view.addSubview(fixedSegmentView)
self.view.addSubview(bottomView)
......@@ -284,6 +313,12 @@ class YHPlanViewController: YHBaseViewController {
make.bottom.equalTo(bottomView.snp.top)
}
fakeTableView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(k_Height_NavigationtBarAndStatuBar+44.0)
make.bottom.equalTo(bottomView.snp.top)
}
fixedSegmentView.snp.makeConstraints { make in
make.left.right.equalToSuperview()
make.top.equalTo(k_Height_NavigationtBarAndStatuBar)
......@@ -345,13 +380,15 @@ class YHPlanViewController: YHBaseViewController {
analyzeArr.removeAll()
analyzeArr.append(contentsOf: [workModel, liveModel, investModel, stayModel])
policyVieiw.bannerArr = policyArr
policyArr.removeAll()
policyArr.append(contentsOf: self.viewModel.planListModel.plan_article_policy)
caseArr.removeAll()
caseArr.append(contentsOf: self.viewModel.planListModel.plan_article_case)
self.tableView.reloadData()
policyVieiw.bannerArr = policyArr
self.tableView.reloadData()
self.fakeTableView.reloadData()
}
}
}
......@@ -389,6 +426,14 @@ extension YHPlanViewController: UITableViewDelegate, UITableViewDataSource {
return UITableViewCell()
}
cell3.cases = self.caseArr
cell3.clickBlock = {
[weak self] arr, index in
guard let self = self else { return }
let vc = YHPlanPolicyDetailViewController()
vc.arr = arr
vc.currentIndex = index
self.navigationController?.pushViewController(vc, animated: true)
}
return cell3
}
}
......@@ -474,45 +519,53 @@ extension YHPlanViewController: UIScrollViewDelegate {
printLog("\(scrollView.contentOffset.y)")
bgImgView.y = scrollView.contentOffset.y > 0.0 ? -scrollView.contentOffset.y : 0.0
if scrollView == tableView {
if scrollView.contentOffset.y >= topScrollHeight {
tableView.contentOffset.y = topScrollHeight
}
var percent = scrollView.contentOffset.y/20.0
if percent > 1.0 {
percent = 1.0
} else if percent < 0.0 {
percent = 0.0
}
fixedSegmentView.alpha = scrollView.contentOffset.y >= topScrollHeight ? 1.0 : 0.0
gk_navigationBar.alpha = percent
whiteBackBtn.isHidden = percent >= 1.0
shareBtn.isHidden = percent >= 1.0
}
var percent = scrollView.contentOffset.y/20.0
if percent > 1.0 {
percent = 1.0
} else if percent < 0.0 {
percent = 0.0
if fakeTableView.contentOffset.y > 0 {
bgImgView.y = -scrollView.contentOffset.y-fakeTableView.contentOffset.y
} else {
bgImgView.y = -scrollView.contentOffset.y
}
fixedSegmentView.alpha = scrollView.contentOffset.y >= topScrollHeight ? 1.0 : 0.0
gk_navigationBar.alpha = percent
whiteBackBtn.isHidden = percent >= 1.0
shareBtn.isHidden = percent >= 1.0
if scrollView.contentOffset.y > topScrollHeight {
if topScrollHeight <= scrollView.contentOffset.y, scrollView.contentOffset.y <= topScrollHeight+10 {
if !contentOffSetChangeBig {
contentOffSetChangeBig = true
tableView.y = k_Height_NavigationtBarAndStatuBar+44.0
printLog("BBBBBBBBB")
tableView.setContentOffset(CGPoint(x: 0, y: headerViewHeight), animated: false)
}
}
fakeTableView.isHidden = tableView.contentOffset.y <= topScrollHeight-1
if tableView.contentOffset.y >= topScrollHeight, fakeTableView.contentOffset.y >= 0 {
tableView.isHidden = true
fakeTableView.isHidden = false
} else {
tableView.isHidden = false
fakeTableView.isHidden = true
}
if scrollView.contentOffset.y < headerViewHeight {
if contentOffSetChangeBig {
contentOffSetChangeBig = false
tableView.y = k_Height_NavigationtBarAndStatuBar
printLog("AAAAAAAAAA")
tableView.setContentOffset(CGPoint(x: 0, y: topScrollHeight), animated: false)
}
}
printLog("fakeTableView: \(fakeTableView.contentOffset.y) tableView: \(tableView.contentOffset.y)")
}
func scrollViewWillEndDragging(_ scrollView: UIScrollView, withVelocity velocity: CGPoint, targetContentOffset: UnsafeMutablePointer<CGPoint>) {
var find = false
for index in 0...infoArr.count-1 {
let rect = self.tableView.rectForRow(at: IndexPath(row: 0, section: index))
let rect = self.fakeTableView.rectForRow(at: IndexPath(row: 0, section: index))
let conditon = index == 0 ? scrollView.contentOffset.y <= rect.origin.y : scrollView.contentOffset.y < rect.origin.y-5
let conditon = index == 0 ? fakeTableView.contentOffset.y <= rect.origin.y : fakeTableView.contentOffset.y < rect.origin.y-5
if conditon {
find = true
let targetIndex = index-1 >= 0 ? index-1 : 0
......@@ -530,6 +583,7 @@ extension YHPlanViewController: UIScrollViewDelegate {
self.segmented1View.defaultSelectedIndex = infoArr.count-1
self.segmented1View.reloadDataWithoutListContainer()
}
}
}
......@@ -538,12 +592,8 @@ extension YHPlanViewController: JXSegmentedViewDelegate {
func segmentedView(_ segmentedView: JXSegmentedView, didSelectedItemAt index: Int) {
let index = segmentedView.selectedIndex
if index > 0 {
if self.tableView.contentOffset.y < topScrollHeight {
self.tableView.setContentOffset(CGPoint(x: 0, y: topScrollHeight+2), animated: false)
}
}
self.tableView.scrollToRow(at: IndexPath(row: 0, section: index), at: .top, animated: true)
self.tableView.setContentOffset(CGPoint(x: 0, y: topScrollHeight), animated: true)
self.fakeTableView.scrollToRow(at: IndexPath(row: 0, section: index), at: .top, animated: true)
if segmentedView == segmented1View {
self.segmented2View.defaultSelectedIndex = index
......
......@@ -12,6 +12,7 @@ class YHPlanCustomerCaseListCell: UITableViewCell {
static let cellReuseIdentifier = "YHPlanCustomerCaseListCell"
var clickBlock: (([YHPlanCaseModel], Int) -> Void)?
var cases: [YHPlanCaseModel] = [] {
didSet {
collectionView.reloadData()
......@@ -130,6 +131,7 @@ extension YHPlanCustomerCaseListCell: UICollectionViewDelegate, UICollectionView
func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
if 0 <= indexPath.item && indexPath.item < cases.count {
// let text = topicArr[indexPath.item]
clickBlock?(cases, indexPath.item)
}
}
......
......@@ -11,6 +11,8 @@ import FSPagerView
class YHPlanPolicyCarouselView: UIView {
var clickBlock: (([YHPlanCaseModel], Int) -> Void)?
var bannerArr: [YHPlanCaseModel] = [] {
didSet {
// 设置为0是先停掉自动滑动定时器
......@@ -139,7 +141,7 @@ extension YHPlanPolicyCarouselView: FSPagerViewDataSource, FSPagerViewDelegate {
pagerView.scrollToItem(at: index, animated: true)
if 0 <= index, index < bannerArr.count {
let model = bannerArr[index]
// selectBannerItemBlock?(model)
clickBlock?(bannerArr, index)
return
}
}
......
......@@ -15,13 +15,13 @@ class YHPlanShareImageCell: UICollectionViewCell {
var model: YHPlanPolicyImageInfo = YHPlanPolicyImageInfo() {
didSet {
if let url = URL(string: model.url) {
if let url = URL(string: model.model.img_url) {
imgView.kf.setImage(with: url, placeholder: UIImage(named: "global_default_image"))
} else {
imgView.image = UIImage(named: "global_default_image")
}
imgView.snp.remakeConstraints { make in
imgView.snp.updateConstraints { make in
make.top.bottom.equalToSuperview()
make.centerX.equalToSuperview()
make.width.equalTo(imgView.snp.height).multipliedBy(model.width/model.height)
......
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