Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
G
galaxy-iOS
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
mobile-group
galaxy-iOS
Commits
0af4620b
Commit
0af4620b
authored
Apr 10, 2024
by
pete谢兆麟
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit '
15fb8b14
' into xiezhaolin
parents
65988f57
15fb8b14
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
140 additions
and
145 deletions
+140
-145
YHHomePageViewController.swift
...Classes/Modules/Home(首页)/C/YHHomePageViewController.swift
+57
-102
YHHomeListModel.swift
...y/galaxy/Classes/Modules/Home(首页)/M/YHHomeListModel.swift
+52
-2
YHHomePageViewModel.swift
...axy/Classes/Modules/Home(首页)/VM/YHHomePageViewModel.swift
+3
-3
YHHomeCollectionViewCell.swift
...IntelligentService(服务中心)/V/YHHomeCollectionViewCell.swift
+28
-38
No files found.
galaxy/galaxy/Classes/Modules/Home(首页)/C/YHHomePageViewController.swift
View file @
0af4620b
...
...
@@ -18,35 +18,13 @@ class YHHomePageViewController: YHBaseViewController {
}()
lazy
var
homeCollectView
=
{
// // 设置布局方向
// let flowLayout = UICollectionViewFlowLayout()
// let margin = 20.0
// let gap = 20.0
// let itemWidth = ceil((KScreenWidth - 2*margin - gap)/2.0)
// flowLayout.itemSize = CGSize(width: itemWidth, height: 210 + 87 + 4)
// flowLayout.minimumInteritemSpacing = 10.0
// flowLayout.minimumLineSpacing = 10.0
// flowLayout.scrollDirection = .vertical
//
// let collectinoView = UICollectionView(frame: .zero, collectionViewLayout: flowLayout)
// collectinoView.backgroundColor = .white
// collectinoView.register(YHDavidTestCollectionViewCell.self, forCellWithReuseIdentifier:YHDavidTestCollectionViewCell.cellReuseIdentifier)
// collectinoView.delegate = self
// collectinoView.dataSource = self
// collectinoView.showsVerticalScrollIndicator = false
//
// collectinoView.translatesAutoresizingMaskIntoConstraints = false
// collectinoView.alwaysBounceVertical = true
//
// 设置布局方向
let
flowLayout
=
YHHomeCollectionLayout
()
flowLayout
.
minimumInteritemSpacing
=
7.0
flowLayout
.
minimumColumnSpacing
=
10.0
flowLayout
.
sectionInset
=
UIEdgeInsets
(
top
:
0
,
left
:
20
,
bottom
:
0
,
right
:
20
)
let
collectinoView
=
YHGestureCollectionView
(
frame
:
.
zero
,
collectionViewLayout
:
flowLayout
)
// collectinoView.contentInset = UIEdgeInsets(top: 20, left: 20, bottom: 20, right: 20)
let
collectinoView
=
UICollectionView
(
frame
:
.
zero
,
collectionViewLayout
:
flowLayout
)
collectinoView
.
backgroundColor
=
.
white
collectinoView
.
register
(
YHHomeCollectionViewCell
.
self
,
forCellWithReuseIdentifier
:
YHHomeCollectionViewCell
.
cellReuseIdentifier
)
collectinoView
.
delegate
=
self
...
...
@@ -82,7 +60,7 @@ class YHHomePageViewController: YHBaseViewController {
}
func
getData
()
{
viewModel
.
getHomeList
{[
weak
self
]
success
,
error
in
viewModel
.
getHome
News
List
{[
weak
self
]
success
,
error
in
guard
let
self
=
self
else
{
return
}
self
.
homeCollectView
.
reloadData
()
}
...
...
@@ -91,10 +69,10 @@ class YHHomePageViewController: YHBaseViewController {
self
.
homeHeaderView
.
homeBannerView
.
dataArr
=
self
.
viewModel
.
banners
??
[]
}
viewModel
.
getHomeClassify
{[
weak
self
]
success
,
error
in
guard
let
self
=
self
else
{
return
}
}
//
viewModel.getHomeClassify {[weak self] success, error in
//
guard let self = self else { return }
//
//
}
}
}
...
...
@@ -119,10 +97,10 @@ private extension YHHomePageViewController {
homeHeaderView
.
frame
=
CGRect
(
x
:
20
,
y
:
-
YHHomeHeadView
.
viewH
,
width
:
KScreenWidth
-
40
,
height
:
YHHomeHeadView
.
viewH
)
homeCollectView
.
addSubview
(
homeHeaderView
)
homeCollectView
.
contentInset
=
UIEdgeInsets
(
top
:
YHHomeHeadView
.
viewH
,
left
:
0
,
bottom
:
0
,
right
:
0
)
homeCollectView
.
contentInset
=
UIEdgeInsets
(
top
:
YHHomeHeadView
.
viewH
,
left
:
0
,
bottom
:
2
0
,
right
:
0
)
homeCollectView
.
es
.
addInfiniteScrolling
{
self
.
loadFakeData
()
//
self.loadFakeData()
}
loadFirstItem
()
homeCollectView
.
reloadData
()
...
...
@@ -138,95 +116,72 @@ private extension YHHomePageViewController {
}
func
loadFakeData
()
{
DispatchQueue
.
main
.
asyncAfter
(
deadline
:
.
now
()
+
1
)
{
self
.
items
.
append
(
AboutAdvantageItem
(
iconName
:
"about_match"
,
title
:
"精准匹配"
,
detail
:
"大数据精准匹配,专属方案获批率更高"
,
url
:
""
))
self
.
items
.
append
(
AboutAdvantageItem
(
iconName
:
"about_match"
,
title
:
"精准匹配"
,
detail
:
"大数据精准匹配,专属方案获批率更高"
,
url
:
""
))
self
.
items
.
append
(
AboutAdvantageItem
(
iconName
:
"about_match"
,
title
:
"精准匹配"
,
detail
:
"大数据精准匹配,专属方案获批率更高"
,
url
:
""
))
self
.
items
.
append
(
AboutAdvantageItem
(
iconName
:
"about_match"
,
title
:
"精准匹配"
,
detail
:
"大数据精准匹配,专属方案获批率更高"
,
url
:
""
))
self
.
items
.
append
(
AboutAdvantageItem
(
iconName
:
"about_match"
,
title
:
"精准匹配"
,
detail
:
"大数据精准匹配,专属方案获批率更高"
,
url
:
""
))
self
.
homeCollectView
.
es
.
stopLoadingMore
()
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
)
}
// 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
{
func
collectionView
(
_
collectionView
:
UICollectionView
,
numberOfItemsInSection
section
:
Int
)
->
Int
{
return
self
.
viewModel
.
lists
?
.
count
??
0
return
self
.
viewModel
.
arrHomeNewsData
.
count
}
func
collectionView
(
_
collectionView
:
UICollectionView
,
cellForItemAt
indexPath
:
IndexPath
)
->
UICollectionViewCell
{
let
cell
=
collectionView
.
dequeueReusableCell
(
withReuseIdentifier
:
YHHomeCollectionViewCell
.
cellReuseIdentifier
,
for
:
indexPath
)
as!
YHHomeCollectionViewCell
cell
.
listModel
=
self
.
viewModel
.
lists
?
[
indexPath
.
row
]
cell
.
listModel
=
self
.
viewModel
.
arrHomeNewsData
[
indexPath
.
row
]
return
cell
}
// func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
// print("index is \(indexPath.row)")
// }
}
extension
YHHomePageViewController
:
CollectionViewWaterfallLayoutDelegate
{
func
collectionView
(
_
collectionView
:
UICollectionView
,
layout
:
UICollectionViewLayout
,
sizeForItemAtIndexPath
indexPath
:
NSIndexPath
)
->
CGSize
{
guard
let
model
=
self
.
viewModel
.
lists
?[
indexPath
.
row
]
else
{
return
CGSize
(
width
:
0
,
height
:
0
)
}
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
}
let
imageSize
=
getImageSize
(
model
.
img_url
)
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
+
46
return
CGSize
(
width
:
width
,
height
:
totalHeight
)
// let margin = 20.0
// let gap = 7.0
// let itemWidth = ceil((KScreenWidth - 2*margin - gap)/2.0)
// let arrItemH : [CGFloat] = [100,150,200,250,300,350,400]
// 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 HHH = arrItemH[Int.random(in: 0...6)]
// return CGSize(width: itemWidth, height: HHH)
// 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
)
}
}
galaxy/galaxy/Classes/Modules/Home(首页)/M/YHHomeListModel.swift
View file @
0af4620b
...
...
@@ -16,6 +16,56 @@ class YHHomeListModel: YHBaseModel {
var
view_count
:
Int
=
0
var
img_url
:
String
=
""
var
type
:
Int
=
0
var
img_width
:
Int
=
0
var
img_height
:
Int
=
0
//网络返回的图片宽高
var
img_width
:
CGFloat
=
0
var
img_height
:
CGFloat
=
0
//实际使用的图片宽高
var
img_width_use
:
CGFloat
=
0
var
img_height_use
:
CGFloat
=
0
//cell的宽高
var
img_width_cell
:
CGFloat
=
0
var
img_height_cell
:
CGFloat
=
0
func
calHeightParam
()
{
let
text
=
self
.
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
(
self
.
img_width
),
CGFloat
(
self
.
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
self
.
img_width_use
=
width
self
.
img_height_use
=
imageHeight
self
.
img_width_cell
=
width
self
.
img_height_cell
=
totalHeight
}
}
galaxy/galaxy/Classes/Modules/Home(首页)/VM/YHHomePageViewModel.swift
View file @
0af4620b
...
...
@@ -11,7 +11,7 @@ import UIKit
class
YHHomePageViewModel
:
YHBaseViewModel
{
//数据源
var
configModel
:
YHHomeCofigMode
?
var
lists
:
[
YHHomeListModel
]?
var
arrHomeNewsData
:
[
YHHomeListModel
?]
=
[]
var
banners
:
[
YHBannerModel
]?
var
classify
:
[
YHHomeClassifyModel
]?
}
...
...
@@ -38,7 +38,7 @@ extension YHHomePageViewModel {
}
}
func
getHomeList
(
callBackBlock
:
@escaping
(
_
success
:
Bool
,
_
error
:
YHErrorModel
?)
->
())
{
func
getHome
News
List
(
callBackBlock
:
@escaping
(
_
success
:
Bool
,
_
error
:
YHErrorModel
?)
->
())
{
let
params
:
[
String
:
Any
]
=
[
"page"
:
1
,
"page_size"
:
10
]
let
strUrl
=
YHBaseUrlManager
.
shared
.
curURL
()
+
YHAllApiName
.
Common
.
consult
...
...
@@ -51,7 +51,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
)
...
...
galaxy/galaxy/Classes/Modules/IntelligentService(服务中心)/V/YHHomeCollectionViewCell.swift
View file @
0af4620b
...
...
@@ -12,11 +12,11 @@ import Kingfisher
class
YHHomeCollectionViewCell
:
UICollectionViewCell
{
static
let
cellReuseIdentifier
=
"YHHomeCollectionViewCell"
var
dataSource
:
AboutAdvantageItem
?
{
didSet
{
updataAllSubViews
()
}
}
//
var dataSource: AboutAdvantageItem? {
//
didSet {
//
updataAllSubViews()
//
}
//
}
var
listModel
:
YHHomeListModel
?
{
didSet
{
...
...
@@ -138,48 +138,38 @@ class YHHomeCollectionViewCell: UICollectionViewCell {
}
func
updataAllSubViews
()
{
guard
let
dataSource
=
dataSource
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 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
}
let
imageSize
=
getImageSize
(
listModel
.
img_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
)
make
.
height
.
equalTo
(
listModel
.
img_height_use
)
}
if
let
url
=
URL
(
string
:
listModel
.
img_url
)
{
titleImageView
.
kf
.
setImage
(
with
:
url
)
}
descripeLable
.
text
=
listModel
.
title
descripeLable
.
text
=
listModel
.
title
.
defaultStringIfEmpty
(
detaultValue
:
"***"
)
//for test hjl
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment