Commit 10ac4cad authored by David黄金龙's avatar David黄金龙

首页细节调试

parent 15fb8b14
......@@ -62,17 +62,15 @@ class YHHomePageViewController: YHBaseViewController {
func getData() {
viewModel.getHomeNewsList {[weak self] success, error in
guard let self = self else { return }
self.homeCollectView.reloadData()
// DispatchQueue.main.async {
self.homeCollectView.reloadData()
// }
}
viewModel.getHomeBanner(0) {[weak self] success, error in
guard let self = self else { return }
self.homeHeaderView.homeBannerView.dataArr = self.viewModel.banners ?? []
}
// viewModel.getHomeClassify {[weak self] success, error in
// guard let self = self else { return }
//
// }
}
}
......@@ -100,40 +98,15 @@ private extension YHHomePageViewController {
homeCollectView.contentInset = UIEdgeInsets(top: YHHomeHeadView.viewH, left: 0, bottom: 20, right: 0)
homeCollectView.es.addInfiniteScrolling {
// self.loadFakeData()
// self.loadFakeData()
}
loadFirstItem()
homeCollectView.reloadData()
}
func loadFirstItem() {
DispatchQueue.main.asyncAfter(deadline: .now() + 1) {
self.items = [AboutAdvantageItem(iconName: "about_match", title: "精准匹配", detail: "大数据精准匹配,专属方案获批率更高", url: ""),AboutAdvantageItem(iconName: "about_match", title: "精准匹配", detail: "大数据精准匹配,专属方案获批率更高", url: ""),AboutAdvantageItem(iconName: "about_match", title: "精准匹配", detail: "大数据精准匹配,专属方案获批率更高", url: ""),AboutAdvantageItem(iconName: "about_match", title: "精准匹配", detail: "大数据精准匹配,专属方案获批率更高", url: "")]
self.homeCollectView.es.stopPullToRefresh(ignoreDate: true,ignoreFooter: false)
self.homeCollectView.reloadData()
}
}
// func getImageSize(_ url: String?) -> CGSize {
// guard let urlStr = url, urlStr.count != 0 else {
// return CGSize.zero
// }
// let tempUrl = URL(string: urlStr)
// let imageSourceRef = CGImageSourceCreateWithURL(tempUrl! as CFURL, nil)
// var width: CGFloat = 0
// var height: CGFloat = 0
// if let imageSRef = imageSourceRef {
// let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSRef, 0, nil)
// if let imageP = imageProperties {
// let imageDict = imageP as Dictionary
// width = imageDict[kCGImagePropertyPixelWidth] as! CGFloat
// height = imageDict[kCGImagePropertyPixelHeight] as! CGFloat
// }
// }
// return CGSize(width: width, height: height)
// }
}
extension YHHomePageViewController: UICollectionViewDelegate, UICollectionViewDataSource {
......@@ -150,38 +123,9 @@ extension YHHomePageViewController: UICollectionViewDelegate, UICollectionViewDa
}
}
extension YHHomePageViewController : CollectionViewWaterfallLayoutDelegate {
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
// let model = self.viewModel.arrHomeNewsData[indexPath.row]
// let text = model.title
// let width = (KScreenWidth - 47) / 2
// let font = UIFont.PFSC_R(ofSize: 14) // 字体大小
// let maxWidth = width - 16 // 最大宽度限制
// // 创建NSAttributedString对象并设置属性
// let attributes = [NSAttributedString.Key.font : font] as [NSAttributedString.Key : Any]
// _ = NSMutableAttributedString(string: text, attributes: attributes)
// // 根据指定的最大宽度和字体大小计算文本的高度
// let size = (text as NSString).boundingRect(with: CGSize(width: maxWidth, height: .greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: attributes, context: nil).size
// var textHeight = size.height
// if textHeight > 40 {
// textHeight = 40
// } else if textHeight < 20 {
// textHeight = 20
// }
//
// let imageSize = CGSizeMake(CGFloat(model.img_width), CGFloat(model.img_height))
// var imageHeight = 0.0
// if imageSize.width == 0 {
// imageHeight = width
// } else {
// imageHeight = width * imageSize.height/imageSize.width
// if imageHeight > 280 {
// imageHeight = 280
// }
// }
// let totalHeight = imageHeight + textHeight + 30
guard let model = self.viewModel.arrHomeNewsData[indexPath.row] else { return CGSize.zero }
return CGSize(width: model.img_width_use, height: model.img_height_use)
return CGSize(width: model.img_width_cell, height: model.img_height_cell)
}
}
......@@ -29,6 +29,9 @@ class YHHomeListModel: YHBaseModel {
var img_width_cell : CGFloat = 0
var img_height_cell : CGFloat = 0
//描述的高度
var textH : CGFloat = 20.0
......@@ -42,12 +45,13 @@ class YHHomeListModel: YHBaseModel {
_ = NSMutableAttributedString(string: text, attributes: attributes)
// 根据指定的最大宽度和字体大小计算文本的高度
let size = (text as NSString).boundingRect(with: CGSize(width: maxWidth, height: .greatestFiniteMagnitude), options: .usesLineFragmentOrigin, attributes: attributes, context: nil).size
var textHeight = size.height
if textHeight > 40 {
textHeight = 40
} else if textHeight < 20 {
textHeight = 20
var textHeight : CGFloat = size.height
if textHeight > 40.0 {
textHeight = 40.0
} else if textHeight < 20.0 {
textHeight = 20.0
}
self.textH = textHeight
let imageSize = CGSizeMake(CGFloat(self.img_width), CGFloat(self.img_height))
var imageHeight = 0.0
......@@ -60,7 +64,7 @@ class YHHomeListModel: YHBaseModel {
}
}
let totalHeight = imageHeight + textHeight + 30
let totalHeight = imageHeight + textHeight + 30 + 18
self.img_width_use = width
self.img_height_use = imageHeight
......
......@@ -48,12 +48,18 @@ extension YHHomePageViewModel {
if json.code == 200 {
let dic = json.data
guard let result = [YHHomeListModel].deserialize(from: dic as? [Any]) else {
self.arrHomeNewsData = []
callBackBlock(false,nil)
return
}
for item in result {
item?.calHeightParam()
}
self.arrHomeNewsData = result
callBackBlock(true, nil)
} else {
self.arrHomeNewsData = []
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
callBackBlock(false, error)
}
......@@ -123,7 +129,7 @@ extension YHHomePageViewModel {
callBackBlock(false,nil)
return
}
self.lists = result as? [YHHomeListModel]
self.arrHomeNewsData = result
callBackBlock(true, nil)
} else {
let error : YHErrorModel = YHErrorModel(errorCode:Int32(json.code), errorMsg: json.msg)
......
......@@ -15,7 +15,7 @@ class YHServerHKLifeViewController: YHBaseViewController {
var tableFootView: YHServiceTableFootView!
var sectionView: YHServiceSectionView!
var dataSouce: [YHHomeListModel] = [] {
var dataSouce: [YHHomeListModel?] = [] {
didSet {
self.homeTableView.reloadData()
}
......@@ -63,7 +63,7 @@ extension YHServerHKLifeViewController {
let classifyID = model.children.first?.id ?? 0
self.homeViewModel.getList(classifyID) {[weak self] success, error in
guard let self = self else { return }
self.dataSouce = self.homeViewModel.lists ?? []
self.dataSouce = self.homeViewModel.arrHomeNewsData
}
}
}
......@@ -80,7 +80,7 @@ extension YHServerHKLifeViewController {
guard let self = self else { return }
self.homeViewModel.getList(model.id) {[weak self] success, error in
guard let self = self else { return }
self.dataSouce = self.homeViewModel.lists ?? []
self.dataSouce = self.homeViewModel.arrHomeNewsData
}
}
return view
......
......@@ -47,7 +47,7 @@ extension YHServiceListViewController {
let classifyID = model.children.first?.id ?? 0
self.homeViewModel.getList(classifyID) {[weak self] success, error in
guard let self = self else { return }
self.normalView.dataSouce = self.homeViewModel.lists ?? []
self.normalView.dataSouce = self.homeViewModel.arrHomeNewsData
}
}
}
......@@ -89,7 +89,7 @@ extension YHServiceListViewController {
guard let self = self else { return }
self.homeViewModel.getList(model.id) {[weak self] success, error in
guard let self = self else { return }
self.normalView.dataSouce = self.homeViewModel.lists ?? []
self.normalView.dataSouce = self.homeViewModel.arrHomeNewsData
}
}
return view
......
......@@ -12,12 +12,6 @@ import Kingfisher
class YHHomeCollectionViewCell: UICollectionViewCell {
static let cellReuseIdentifier = "YHHomeCollectionViewCell"
// var dataSource: AboutAdvantageItem? {
// didSet {
// updataAllSubViews()
// }
// }
var listModel: YHHomeListModel? {
didSet {
updataSubViews()
......@@ -27,8 +21,6 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
lazy var titleImageView:UIImageView = {
let imageV = UIImageView(image: UIImage(named: "home_title_image"))
imageV.contentMode = .scaleAspectFill
imageV.roundCorners(UIRectCorner.topLeft, radius: 8)
imageV.roundCorners(UIRectCorner.topRight, radius: 8)
return imageV
}()
......@@ -37,49 +29,30 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
let label = UILabel()
label.text = "赴港攻略,当日往返无忧,这个季节风景..赴港攻略,当日往返无忧,这个季节风景"
label.textColor = UIColor(hexString:"#333333")
label.font = UIFont.systemFont(ofSize: 10)
label.font = UIFont.PFSC_R(ofSize: 14)
label.numberOfLines = 2
label.lineBreakMode = .byTruncatingTail
label.lineBreakMode = .byWordWrapping
return label
}()
lazy var headImageView:UIImageView = {
let imageV = UIImageView(image: UIImage(named: "home_person_icon"))
let imageV = UIImageView(image: UIImage(named: ""))
imageV.contentMode = .scaleAspectFill
return imageV
}()
lazy var nameLable:UILabel = {
let label = UILabel()
label.text = "Fiona"
label.textColor = UIColor(hexString:"#333333")
label.font = UIFont.systemFont(ofSize: 10)
return label
}()
lazy var dateLable:UILabel = {
let label = UILabel()
label.text = "12-12"
label.textColor = UIColor(hexString:"#333333")
label.font = UIFont.systemFont(ofSize: 10)
return label
}()
lazy var heartImageView:UIImageView = {
let imageV = UIImageView(image: UIImage(named: "home_red_heart"))
let imageV = UIImageView(image: UIImage(named: "home_grey_heart"))
imageV.contentMode = .scaleAspectFill
return imageV
}()
lazy var numLable:UILabel = {
let label = UILabel()
label.text = "2000"
label.textColor = UIColor(hexString:"#333333")
label.font = UIFont.systemFont(ofSize: 14)
label.text = ""
label.textColor = UIColor(hex: 0x121A264D, alpha: 0.3)
label.font = UIFont.PFSC_R(ofSize: 12)
return label
}()
......@@ -93,21 +66,18 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
}
private func setupUI() {
contentView.backgroundColor = UIColor(hexString: "#F8F9FB")
contentView.roundCorners([.topLeft,.topRight], radius: 4)
contentView.clipsToBounds = true
contentView.addSubview(titleImageView)
titleImageView.snp.makeConstraints { make in
make.left.right.top.equalToSuperview()
make.height.equalTo(210)
}
let subHoldView = UIView()
subHoldView.layer.backgroundColor = UIColor(red: 1, green: 1, blue: 1, alpha: 1).cgColor
subHoldView.layer.borderWidth = 0.5
subHoldView.layer.borderColor = UIColor(red: 0.798, green: 0.798, blue: 0.798, alpha: 1).cgColor
subHoldView.layer.backgroundColor = UIColor.white.cgColor
subHoldView.layer.borderWidth = 0.6
subHoldView.layer.borderColor = UIColor(red: 0.943, green: 0.952, blue: 0.969, alpha: 1).cgColor
contentView.addSubview(subHoldView)
subHoldView.snp.makeConstraints { make in
make.top.equalTo(titleImageView.snp.bottom)
......@@ -119,47 +89,23 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
make.top.equalToSuperview().offset(10)
make.left.equalToSuperview().offset(8)
make.right.equalToSuperview().offset(-8)
make.bottom.equalTo(-36)
}
subHoldView.addSubview(numLable)
numLable.snp.makeConstraints { make in
make.right.equalToSuperview().offset(-8)
make.height.equalTo(12)
make.bottom.equalTo(-10)
make.top.equalTo(descripeLable.snp.bottom).offset(10)
make.height.equalTo(18)
}
subHoldView.addSubview(heartImageView)
heartImageView.snp.makeConstraints { make in
make.right.equalTo(numLable.snp.left).offset(-6)
make.height.width.equalTo(12)
make.bottom.equalTo(-10)
make.right.equalTo(numLable.snp.left).offset(-2)
make.height.width.equalTo(16)
make.centerY.equalTo(numLable)
}
}
// func updataAllSubViews() {
// guard let dataSource = listModel else { return }
// let imageSize = getImageSize(dataSource.url)
// var imageHeight = 0.0
// if imageSize.width == 0 {
// imageHeight = width
// } else {
// imageHeight = width * imageSize.height/imageSize.width
// if imageHeight > 280 {
// imageHeight = 280
// }
// }
// titleImageView.snp.remakeConstraints { make in
// make.left.right.top.equalToSuperview()
// make.height.equalTo(imageHeight)
// }
// if let url = URL(string: dataSource.url) {
// titleImageView.kf.setImage(with: url)
// }
// descripeLable.text = dataSource.title
// }
func updataSubViews() {
guard let listModel = listModel else { return }
titleImageView.snp.remakeConstraints { make in
......@@ -169,27 +115,15 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
if let url = URL(string: listModel.img_url) {
titleImageView.kf.setImage(with: url)
}
descripeLable.text = listModel.title.defaultStringIfEmpty(detaultValue: "***")//for test hjl
}
func getImageSize(_ url: String?) -> CGSize {
// guard let urlStr = url, urlStr.count != 0 else {
// return CGSize.zero
// }
// let tempUrl = URL(string: urlStr)
// let imageSourceRef = CGImageSourceCreateWithURL(tempUrl! as CFURL, nil)
// var width: CGFloat = 0
// var height: CGFloat = 0
// if let imageSRef = imageSourceRef {
// let imageProperties = CGImageSourceCopyPropertiesAtIndex(imageSRef, 0, nil)
// if let imageP = imageProperties {
// let imageDict = imageP as Dictionary
// width = imageDict[kCGImagePropertyPixelWidth] as! CGFloat
// height = imageDict[kCGImagePropertyPixelHeight] as! CGFloat
// }
// }
return CGSize(width: 200, height: 250)
descripeLable.text = listModel.title.defaultStringIfEmpty(detaultValue: "***")
descripeLable.snp.removeConstraints()
descripeLable.snp.remakeConstraints { make in
make.top.equalToSuperview().offset(10)
make.left.equalToSuperview().offset(8)
make.right.equalToSuperview().offset(-8)
make.height.equalTo(listModel.textH)
make.bottom.equalTo(-36)
}
numLable.text = listModel.collect_count.string
}
}
......@@ -14,7 +14,7 @@ class YHServerNoOrderView: UIView {
var tableHeadView: YHServerTableHeadView!
var sectionView: YHServiceSectionView!
var dataSouce: [YHHomeListModel] = [] {
var dataSouce: [YHHomeListModel?] = [] {
didSet {
self.homeTableView.reloadData()
}
......
......@@ -10,7 +10,7 @@ import UIKit
class YHServiceTableFootView: UIView {
var items:[YHHomeListModel] = [] {
var items:[YHHomeListModel?] = [] {
didSet {
self.myCollectView.reloadData()
}
......@@ -98,7 +98,7 @@ extension YHServiceTableFootView: UICollectionViewDelegate, UICollectionViewData
extension YHServiceTableFootView: CollectionViewWaterfallLayoutDelegate {
func collectionView(_ collectionView: UICollectionView, layout: UICollectionViewLayout, sizeForItemAtIndexPath indexPath: NSIndexPath) -> CGSize {
let model = items[indexPath.row]
guard let model = items[indexPath.row] else { return CGSize.zero }
let text = model.title
let width = (KScreenWidth - 47) / 2
let font = UIFont.PFSC_R(ofSize: 14) // 字体大小
......
......@@ -5,12 +5,12 @@
"scale" : "1x"
},
{
"filename" : "Vector@2x.png",
"filename" : "编组-8@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "Vector@3x.png",
"filename" : "编组-8@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
......
{
"images" : [
{
"idiom" : "universal",
"scale" : "1x"
},
{
"filename" : "编组-8@2x.png",
"idiom" : "universal",
"scale" : "2x"
},
{
"filename" : "编组-8@3x.png",
"idiom" : "universal",
"scale" : "3x"
}
],
"info" : {
"author" : "xcode",
"version" : 1
}
}
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