|
@@ -12,6 +12,7 @@ class SearchContentListViewController: UIViewController {
|
|
|
|
|
|
var keyWord : String = ""
|
|
|
var communityPostDataModels = Array<CommunityPostDataModel>()
|
|
|
+ var heights = Array<CGFloat>()
|
|
|
|
|
|
override func viewDidLoad() {
|
|
|
super.viewDidLoad()
|
|
@@ -23,7 +24,7 @@ class SearchContentListViewController: UIViewController {
|
|
|
|
|
|
private func setupViews() {
|
|
|
view.backgroundColor = kf7f8faColor
|
|
|
-
|
|
|
+ view.addSubview(collectionView)
|
|
|
let emptyView = DIYEmptyView.empty(with: kImage(name: "default_page_content"), titleStr: "没有找到相关,去看看别人都在看什么吧~", detailStr: nil)
|
|
|
emptyView!.contentViewY = kScaleValue(value: 141)
|
|
|
collectionView.ly_emptyView = emptyView
|
|
@@ -60,23 +61,12 @@ class SearchContentListViewController: UIViewController {
|
|
|
return collectionView
|
|
|
}()
|
|
|
|
|
|
- private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
|
|
|
- let collectionViewLayout = UICollectionViewFlowLayout.init()
|
|
|
- collectionViewLayout.minimumLineSpacing = 5
|
|
|
- collectionViewLayout.minimumInteritemSpacing = 5
|
|
|
- collectionViewLayout.scrollDirection = UICollectionView.ScrollDirection.vertical
|
|
|
- collectionViewLayout.itemSize = CGSize(width: (kScreenWidth - 15)/2, height: 250)
|
|
|
- collectionViewLayout.sectionInset = UIEdgeInsets(top: 0, left: 5, bottom: kSafeTabBarHeight, right: 5)
|
|
|
-
|
|
|
+ private lazy var collectionViewLayout: WaterFallLayout = {
|
|
|
+ let collectionViewLayout = WaterFallLayout()
|
|
|
+ collectionViewLayout.delegate = self
|
|
|
return collectionViewLayout
|
|
|
}()
|
|
|
|
|
|
-// private lazy var collectionViewLayout: WaterFallLayout = {
|
|
|
-// let collectionViewLayout = WaterFallLayout()
|
|
|
-// collectionViewLayout.delegate = self
|
|
|
-// return collectionViewLayout
|
|
|
-// }()
|
|
|
-
|
|
|
}
|
|
|
|
|
|
extension SearchContentListViewController {
|
|
@@ -89,6 +79,7 @@ extension SearchContentListViewController {
|
|
|
self?.communityPostDataModels.removeAll()
|
|
|
}
|
|
|
self?.communityPostDataModels = (self?.communityPostDataModels)! + (communityPostsModel?.data!)!
|
|
|
+ self?.heightList()
|
|
|
self?.collectionView.reloadData()
|
|
|
if self?.communityPostDataModels.count ?? 0 >= communityPostsModel?.pagination?.total ?? 0 {
|
|
|
self?.collectionView.isHiddenFooter(true)
|
|
@@ -98,12 +89,48 @@ extension SearchContentListViewController {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ /// 获取高度
|
|
|
+ func heightList() {
|
|
|
+ heights.removeAll()
|
|
|
+ if !communityPostDataModels.isEmpty {
|
|
|
+ for (index,communityPostDataModel) in communityPostDataModels.enumerated() {
|
|
|
+ //图片高度
|
|
|
+ var imageHeight : CGFloat!
|
|
|
+ if index == 0 {
|
|
|
+ imageHeight = (kScreenWidth - 15)/2
|
|
|
+ }else {
|
|
|
+ imageHeight = 240 * kScaleWidth
|
|
|
+ }
|
|
|
+
|
|
|
+ //label高度
|
|
|
+ var labelHeight : CGFloat = 0
|
|
|
+ //总间距
|
|
|
+ let spacingHeght : CGFloat!
|
|
|
+
|
|
|
+ if communityPostDataModel.title == "" || communityPostDataModel.title == nil {
|
|
|
+ labelHeight = 0
|
|
|
+ spacingHeght = 25
|
|
|
+ }else {
|
|
|
+ labelHeight = (communityPostDataModel.title?.heightForComment(font: kMediumFont13!, width: (((kScreenWidth - 15)/2) - 20)))!
|
|
|
+ spacingHeght = 35
|
|
|
+ }
|
|
|
+
|
|
|
+ //button高度
|
|
|
+ let buttonHeight = 18
|
|
|
+ let totalHeight = CGFloat(imageHeight!) + CGFloat(labelHeight) + CGFloat(spacingHeght) + CGFloat(buttonHeight)
|
|
|
+ heights.append(totalHeight)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
|
extension SearchContentListViewController : WaterFallLayoutDelegate {
|
|
|
func collectionView(_ collectionView: UICollectionView!, heightOfItemAt indexPath: IndexPath!) -> CGFloat {
|
|
|
- return 250
|
|
|
+ return heights.isEmpty ? 0 : heights[indexPath.row]
|
|
|
}
|
|
|
func contentInsets(for collectionView: UICollectionView!) -> UIEdgeInsets {
|
|
|
return UIEdgeInsets(top: 0, left: 5, bottom: kSafeTabBarHeight, right: 5)
|
|
@@ -122,20 +149,21 @@ extension SearchContentListViewController : WaterFallLayoutDelegate {
|
|
|
extension SearchContentListViewController: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
|
|
|
|
|
|
func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
- return communityPostDataModels.isEmpty ? 0 : 1
|
|
|
-// return 1
|
|
|
+ return 1
|
|
|
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
return communityPostDataModels.isEmpty ? 0 : communityPostDataModels.count
|
|
|
-// return 10
|
|
|
|
|
|
}
|
|
|
|
|
|
func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
let cell = SearchContentListCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
|
cell.communityPostDataModel = communityPostDataModels[indexPath.row]
|
|
|
+ cell.userClosure = {
|
|
|
+ NotificationCenter.default.post(name: NSNotification.Name("OtherPersonalCenter"), object: cell.communityPostDataModel?.uid)
|
|
|
+ }
|
|
|
return cell
|
|
|
}
|
|
|
|