Browse Source

搜索页面完成

南鑫林 5 years ago
parent
commit
269b569425

+ 26 - 4
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchContentList/View/SearchContentListCollectionCell.swift

@@ -26,7 +26,17 @@ class SearchContentListCollectionCell: UICollectionViewCell {
     //MARK: - indexPath
     //MARK: - indexPath
     var indexPath: IndexPath?{
     var indexPath: IndexPath?{
         didSet {
         didSet {
-
+            if indexPath?.row == 0 {
+                contentImageView.snp.remakeConstraints { (make) in
+                    make.top.left.right.equalToSuperview()
+                    make.height.equalTo((kScreenWidth-15)/2)
+                }
+            }else {
+                contentImageView.snp.remakeConstraints { (make) in
+                    make.top.left.right.equalToSuperview()
+                    make.height.equalTo(240*kScaleWidth)
+                }
+            }
         }
         }
     }
     }
     //MARK: - 初始化
     //MARK: - 初始化
@@ -55,7 +65,6 @@ class SearchContentListCollectionCell: UICollectionViewCell {
     private func setupLayouts() {
     private func setupLayouts() {
         contentImageView.snp.makeConstraints { (make) in
         contentImageView.snp.makeConstraints { (make) in
             make.top.left.right.equalToSuperview()
             make.top.left.right.equalToSuperview()
-            make.width.equalTo((kScreenWidth-10-5)/2)
         }
         }
         titleLabel.snp.makeConstraints { (make) in
         titleLabel.snp.makeConstraints { (make) in
             make.top.equalTo(contentImageView.snp_bottom).offset(15)
             make.top.equalTo(contentImageView.snp_bottom).offset(15)
@@ -66,7 +75,6 @@ class SearchContentListCollectionCell: UICollectionViewCell {
             make.top.equalTo(titleLabel.snp_bottom).offset(10)
             make.top.equalTo(titleLabel.snp_bottom).offset(10)
             make.left.equalToSuperview().offset(10)
             make.left.equalToSuperview().offset(10)
             make.size.equalTo(18)
             make.size.equalTo(18)
-            make.bottom.equalToSuperview().offset(-15)
         }
         }
         nameButton.snp.makeConstraints { (make) in
         nameButton.snp.makeConstraints { (make) in
             make.centerY.equalTo(avatarButton)
             make.centerY.equalTo(avatarButton)
@@ -99,11 +107,20 @@ class SearchContentListCollectionCell: UICollectionViewCell {
         return titleLabel
         return titleLabel
     }()
     }()
     
     
+    typealias UserClosure = () -> Void
+    var userClosure : UserClosure?
+    
     private lazy var avatarButton: UIButton = {
     private lazy var avatarButton: UIButton = {
         let avatarButton = UIButton(type: UIButton.ButtonType.custom)
         let avatarButton = UIButton(type: UIButton.ButtonType.custom)
         avatarButton.setImage(kImage(name: "defaul_tavatar"), for: UIControl.State.normal)
         avatarButton.setImage(kImage(name: "defaul_tavatar"), for: UIControl.State.normal)
         avatarButton.cornerRadius = 18/2
         avatarButton.cornerRadius = 18/2
         avatarButton.masksToBounds = true
         avatarButton.masksToBounds = true
+        avatarButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            if let userClosure = self?.userClosure {
+                userClosure()
+            }
+        }).disposed(by: disposeBag)
         return avatarButton
         return avatarButton
     }()
     }()
     
     
@@ -114,12 +131,17 @@ class SearchContentListCollectionCell: UICollectionViewCell {
         nameButton.setTitleColor(k262626Color, for: UIControl.State.normal)
         nameButton.setTitleColor(k262626Color, for: UIControl.State.normal)
         nameButton.titleLabel?.font = kRegularFont12
         nameButton.titleLabel?.font = kRegularFont12
         nameButton.contentHorizontalAlignment = .left
         nameButton.contentHorizontalAlignment = .left
+        nameButton.rx.tap.subscribe(onNext: {
+            [weak self] (data) in
+            if let userClosure = self?.userClosure {
+                userClosure()
+            }
+        }).disposed(by: disposeBag)
         return nameButton
         return nameButton
     }()
     }()
     
     
     private lazy var likeBtn: UIButton = {
     private lazy var likeBtn: UIButton = {
         let likeBtn = UIButton(type: UIButton.ButtonType.custom)
         let likeBtn = UIButton(type: UIButton.ButtonType.custom)
-        likeBtn.setTitle("8844", for: UIControl.State.normal)
         likeBtn.setTitleColor(k999999Color, for: UIControl.State.normal)
         likeBtn.setTitleColor(k999999Color, for: UIControl.State.normal)
         likeBtn.setImage(kImage(name: "btn_praise"), for: UIControl.State.normal)
         likeBtn.setImage(kImage(name: "btn_praise"), for: UIControl.State.normal)
         likeBtn.setImage(kImage(name: "btn_praise_pre_36px"), for: UIControl.State.selected)
         likeBtn.setImage(kImage(name: "btn_praise_pre_36px"), for: UIControl.State.selected)

+ 47 - 19
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchContentList/ViewController/SearchContentListViewController.swift

@@ -12,6 +12,7 @@ class SearchContentListViewController: UIViewController {
 
 
     var keyWord : String = ""
     var keyWord : String = ""
     var communityPostDataModels = Array<CommunityPostDataModel>()
     var communityPostDataModels = Array<CommunityPostDataModel>()
+    var heights = Array<CGFloat>()
     
     
     override func viewDidLoad() {
     override func viewDidLoad() {
         super.viewDidLoad()
         super.viewDidLoad()
@@ -23,7 +24,7 @@ class SearchContentListViewController: UIViewController {
     
     
     private func setupViews() {
     private func setupViews() {
         view.backgroundColor = kf7f8faColor
         view.backgroundColor = kf7f8faColor
-        
+        view.addSubview(collectionView)
         let emptyView = DIYEmptyView.empty(with: kImage(name: "default_page_content"), titleStr: "没有找到相关,去看看别人都在看什么吧~", detailStr: nil)
         let emptyView = DIYEmptyView.empty(with: kImage(name: "default_page_content"), titleStr: "没有找到相关,去看看别人都在看什么吧~", detailStr: nil)
         emptyView!.contentViewY = kScaleValue(value: 141)
         emptyView!.contentViewY = kScaleValue(value: 141)
         collectionView.ly_emptyView = emptyView
         collectionView.ly_emptyView = emptyView
@@ -60,23 +61,12 @@ class SearchContentListViewController: UIViewController {
         return collectionView
         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
         return collectionViewLayout
     }()
     }()
     
     
-//    private lazy var collectionViewLayout: WaterFallLayout = {
-//        let collectionViewLayout = WaterFallLayout()
-//        collectionViewLayout.delegate = self
-//        return collectionViewLayout
-//    }()
-    
 }
 }
 
 
 extension SearchContentListViewController {
 extension SearchContentListViewController {
@@ -89,6 +79,7 @@ extension SearchContentListViewController {
                     self?.communityPostDataModels.removeAll()
                     self?.communityPostDataModels.removeAll()
                 }
                 }
                 self?.communityPostDataModels = (self?.communityPostDataModels)! + (communityPostsModel?.data!)!
                 self?.communityPostDataModels = (self?.communityPostDataModels)! + (communityPostsModel?.data!)!
+                self?.heightList()
                 self?.collectionView.reloadData()
                 self?.collectionView.reloadData()
                 if  self?.communityPostDataModels.count ?? 0 >= communityPostsModel?.pagination?.total ?? 0 {
                 if  self?.communityPostDataModels.count ?? 0 >= communityPostsModel?.pagination?.total ?? 0 {
                     self?.collectionView.isHiddenFooter(true)
                     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 {
 extension SearchContentListViewController : WaterFallLayoutDelegate {
     func collectionView(_ collectionView: UICollectionView!, heightOfItemAt indexPath: IndexPath!) -> CGFloat {
     func collectionView(_ collectionView: UICollectionView!, heightOfItemAt indexPath: IndexPath!) -> CGFloat {
-        return 250
+        return heights.isEmpty ? 0 : heights[indexPath.row]
     }
     }
     func contentInsets(for collectionView: UICollectionView!) -> UIEdgeInsets {
     func contentInsets(for collectionView: UICollectionView!) -> UIEdgeInsets {
         return UIEdgeInsets(top: 0, left: 5, bottom: kSafeTabBarHeight, right: 5)
         return UIEdgeInsets(top: 0, left: 5, bottom: kSafeTabBarHeight, right: 5)
@@ -122,20 +149,21 @@ extension SearchContentListViewController : WaterFallLayoutDelegate {
 extension SearchContentListViewController: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
 extension SearchContentListViewController: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
     
     
     func numberOfSections(in collectionView: UICollectionView) -> Int {
     func numberOfSections(in collectionView: UICollectionView) -> Int {
-        return communityPostDataModels.isEmpty ? 0 : 1
-//        return 1
+        return 1
 
 
     }
     }
     
     
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
     func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
         return communityPostDataModels.isEmpty ? 0 : communityPostDataModels.count
         return communityPostDataModels.isEmpty ? 0 : communityPostDataModels.count
-//        return 10
 
 
     }
     }
     
     
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
     func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
         let cell = SearchContentListCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
         let cell = SearchContentListCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
         cell.communityPostDataModel = communityPostDataModels[indexPath.row]
         cell.communityPostDataModel = communityPostDataModels[indexPath.row]
+        cell.userClosure = {
+            NotificationCenter.default.post(name: NSNotification.Name("OtherPersonalCenter"), object: cell.communityPostDataModel?.uid)
+        }
         return cell
         return cell
     }
     }
     
     

+ 3 - 3
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchResult/ViewController/SearchResultViewController.swift

@@ -79,10 +79,10 @@ class SearchResultViewController: BaseViewController {
         // 用户页面
         // 用户页面
         observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("OtherPersonalCenter"), object: nil, queue: OperationQueue.main) {
         observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("OtherPersonalCenter"), object: nil, queue: OperationQueue.main) {
             [weak self] (notification) in
             [weak self] (notification) in
-            let searchMemberModel = notification.object as! SearchMemberModel
-            if searchMemberModel.uid != UserModel.shared().getModel()?.uid {
+            let uid = notification.object as! Int
+            if uid != UserModel.shared().getModel()?.uid {
                 let vc = OtherPersonalCenterViewController()
                 let vc = OtherPersonalCenterViewController()
-                vc.uid = searchMemberModel.uid ?? 0
+                vc.uid = uid
                 self?.navigationController?.pushViewController(vc, animated: true)
                 self?.navigationController?.pushViewController(vc, animated: true)
             }
             }
         }
         }

+ 1 - 1
RainbowPlanet/RainbowPlanet/Modules/SearchModule/SearchUser/ViewController/SearchUserListViewController.swift

@@ -136,7 +136,7 @@ extension SearchUserListViewController :UITableViewDataSource,UITableViewDelegat
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         tableView.deselectRow(at: indexPath, animated: true)
         tableView.deselectRow(at: indexPath, animated: true)
         let searchMemberModel = searchMemberModels[indexPath.row]
         let searchMemberModel = searchMemberModels[indexPath.row]
-        NotificationCenter.default.post(name: NSNotification.Name("OtherPersonalCenter"), object: searchMemberModel)
+        NotificationCenter.default.post(name: NSNotification.Name("OtherPersonalCenter"), object: searchMemberModel.uid)
 
 
     }
     }