浏览代码

cell嵌套collection -- to be fixed

Chris 5 年之前
父节点
当前提交
e36f7fcdf7

+ 4 - 4
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -366,6 +366,7 @@
 		BD12204B22AF99C80051C7C2 /* MessageFollowNotiTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD12204A22AF99C80051C7C2 /* MessageFollowNotiTableCell.swift */; };
 		BD12204E22AFB07E0051C7C2 /* MessageThumbController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD12204D22AFB07E0051C7C2 /* MessageThumbController.swift */; };
 		BD12205022AFB08B0051C7C2 /* MessageThumbTableCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD12204F22AFB08B0051C7C2 /* MessageThumbTableCell.swift */; };
+		BD12B66922B47D4800AEB10B /* RecommendSubCommentCollectionCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD12B66822B47D4700AEB10B /* RecommendSubCommentCollectionCell.swift */; };
 		BD1DC6C5228CFD0B00B89C57 /* SwiftMoyaNetWorkServiceOrder.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD1DC6C3228CFD0B00B89C57 /* SwiftMoyaNetWorkServiceOrder.swift */; };
 		BD1DC6C6228CFD0B00B89C57 /* SwiftMoyaServiceOrderApi.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD1DC6C4228CFD0B00B89C57 /* SwiftMoyaServiceOrderApi.swift */; };
 		BD1DC6C9228D005000B89C57 /* OrderCreateParameterModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BD1DC6C8228D005000B89C57 /* OrderCreateParameterModel.swift */; };
@@ -416,7 +417,6 @@
 		BDAF83B022B3B63B0004BCC3 /* RecommendCommentHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDAF83AF22B3B63B0004BCC3 /* RecommendCommentHeader.swift */; };
 		BDAF83B222B3B67D0004BCC3 /* RecommendCommentFooter.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDAF83B122B3B67D0004BCC3 /* RecommendCommentFooter.swift */; };
 		BDAF83B422B3B6DF0004BCC3 /* RecommendMajorCommentCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDAF83B322B3B6DF0004BCC3 /* RecommendMajorCommentCell.swift */; };
-		BDAF83B622B3B7010004BCC3 /* RecommendSubCommentCell.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDAF83B522B3B7010004BCC3 /* RecommendSubCommentCell.swift */; };
 		BDD22F0B228FAA5B00D43BFB /* ImageUrlModel.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD22F0A228FAA5B00D43BFB /* ImageUrlModel.swift */; };
 		BDD4FB1222840597006FE833 /* ShoppingCartPayOrderController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD4FB1122840597006FE833 /* ShoppingCartPayOrderController.swift */; };
 		BDD4FB1422840954006FE833 /* ShoppingCartOrderPayView.swift in Sources */ = {isa = PBXBuildFile; fileRef = BDD4FB1322840954006FE833 /* ShoppingCartOrderPayView.swift */; };
@@ -837,6 +837,7 @@
 		BD12204A22AF99C80051C7C2 /* MessageFollowNotiTableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageFollowNotiTableCell.swift; sourceTree = "<group>"; };
 		BD12204D22AFB07E0051C7C2 /* MessageThumbController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageThumbController.swift; sourceTree = "<group>"; };
 		BD12204F22AFB08B0051C7C2 /* MessageThumbTableCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MessageThumbTableCell.swift; sourceTree = "<group>"; };
+		BD12B66822B47D4700AEB10B /* RecommendSubCommentCollectionCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendSubCommentCollectionCell.swift; sourceTree = "<group>"; };
 		BD1DC6C3228CFD0B00B89C57 /* SwiftMoyaNetWorkServiceOrder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftMoyaNetWorkServiceOrder.swift; sourceTree = "<group>"; };
 		BD1DC6C4228CFD0B00B89C57 /* SwiftMoyaServiceOrderApi.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SwiftMoyaServiceOrderApi.swift; sourceTree = "<group>"; };
 		BD1DC6C8228D005000B89C57 /* OrderCreateParameterModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OrderCreateParameterModel.swift; sourceTree = "<group>"; };
@@ -893,7 +894,6 @@
 		BDAF83AF22B3B63B0004BCC3 /* RecommendCommentHeader.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendCommentHeader.swift; sourceTree = "<group>"; };
 		BDAF83B122B3B67D0004BCC3 /* RecommendCommentFooter.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendCommentFooter.swift; sourceTree = "<group>"; };
 		BDAF83B322B3B6DF0004BCC3 /* RecommendMajorCommentCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendMajorCommentCell.swift; sourceTree = "<group>"; };
-		BDAF83B522B3B7010004BCC3 /* RecommendSubCommentCell.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RecommendSubCommentCell.swift; sourceTree = "<group>"; };
 		BDD22F0A228FAA5B00D43BFB /* ImageUrlModel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImageUrlModel.swift; sourceTree = "<group>"; };
 		BDD4FB1122840597006FE833 /* ShoppingCartPayOrderController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingCartPayOrderController.swift; sourceTree = "<group>"; };
 		BDD4FB1322840954006FE833 /* ShoppingCartOrderPayView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ShoppingCartOrderPayView.swift; sourceTree = "<group>"; };
@@ -3469,8 +3469,8 @@
 			children = (
 				BDAF83AF22B3B63B0004BCC3 /* RecommendCommentHeader.swift */,
 				BDAF83B322B3B6DF0004BCC3 /* RecommendMajorCommentCell.swift */,
-				BDAF83B522B3B7010004BCC3 /* RecommendSubCommentCell.swift */,
 				BDAF83B122B3B67D0004BCC3 /* RecommendCommentFooter.swift */,
+				BD12B66822B47D4700AEB10B /* RecommendSubCommentCollectionCell.swift */,
 			);
 			path = "全部评论的Cell";
 			sourceTree = "<group>";
@@ -4093,6 +4093,7 @@
 				A72A72C622321DE000B21995 /* WebView.swift in Sources */,
 				A72A72D122321E2700B21995 /* HTMLURLMacro.swift in Sources */,
 				BD1FC1A622B1075F00D55081 /* LxButton.m in Sources */,
+				BD12B66922B47D4800AEB10B /* RecommendSubCommentCollectionCell.swift in Sources */,
 				BDF862A1228E41CC000DEF84 /* OrderLogisticsController.swift in Sources */,
 				A72A73162232481600B21995 /* WeChatpayManager.swift in Sources */,
 				A7CC750F22715AAC003C4F38 /* MessageDetailesTableViewCell.swift in Sources */,
@@ -4170,7 +4171,6 @@
 				A71AF0A6226EDDC8001730FE /* SearchViewController.swift in Sources */,
 				BD20F1CF2283CE2300677D8E /* OrderFinishPayView.swift in Sources */,
 				A7A98E4322804851005306E9 /* ShoppingMallSepcialFlowLayout.swift in Sources */,
-				BDAF83B622B3B7010004BCC3 /* RecommendSubCommentCell.swift in Sources */,
 				BD12204122AF8E320051C7C2 /* MessagePlanetNotiTableCell.swift in Sources */,
 				A79057062276EA3D0037F823 /* OpenCityListModel.swift in Sources */,
 				BD7AB838228420310030646A /* ShoppingCartPayOrderHeader.swift in Sources */,

+ 9 - 2
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/Controller/CommunityRecommendController.swift

@@ -47,7 +47,7 @@ class CommunityRecommendController: BaseViewController {
         tableView.backgroundColor = kf7f8faColor
         tableView.dataSource = self
         tableView.delegate = self
-        tableView.estimatedRowHeight = 200
+        tableView.estimatedRowHeight = UITableView.automaticDimension
         tableView.estimatedSectionFooterHeight = 0.000001
         tableView.estimatedSectionHeaderHeight = 0.000001
         return tableView
@@ -113,10 +113,17 @@ extension CommunityRecommendController: UITableViewDataSource, UITableViewDelega
             }
             return cell
         case 3:
-            let cell = CommunityMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
+            let cell = RecommendMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath)
+            if indexPath.row == 2 || indexPath.row == 0 {
+                cell.subCommentCount = 3
+            }
+            cell.frame = tableView.bounds
+            cell.layoutIfNeeded()
+            cell.reloadData()
             return cell
         case 4:
             let cell = RecommendSimilarCell.cellWith(tableView: tableView, indexPath: indexPath)
+            cell.frame = tableView.bounds
             cell.layoutIfNeeded()
             cell.reloadData()
             return cell

+ 80 - 1
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/全部评论的Cell/RecommendMajorCommentCell.swift

@@ -10,6 +10,27 @@ import UIKit
 
 class RecommendMajorCommentCell: UITableViewCell {
     
+    var subCommentCount: Int = 0 {
+        didSet {
+            if subCommentCount != 0 {
+                self.addSubview(collectionView)
+                timeLabel.snp.remakeConstraints { (make) in
+                    make.top.equalTo(contentLabel.snp_bottom).offset(8)
+                    make.left.equalTo(titleLabel.snp_left)
+                    make.right.equalTo(contentLabel.snp_right)
+                    make.height.equalTo(15)
+                }
+                collectionView.snp.makeConstraints { (make) in
+                    make.top.equalTo(timeLabel.snp_bottom).offset(10)
+                    make.left.equalTo(contentLabel.snp_left)
+                    make.right.equalTo(contentLabel.snp_right)
+                    make.bottom.equalTo(-20)
+                }
+//                collectionView.reloadData()
+            }
+        }
+    }
+    
     class func cellWith(tableView:UITableView,indexPath:IndexPath) -> RecommendMajorCommentCell {
         let ID = "RecommendMajorCommentCell"
         tableView.register(RecommendMajorCommentCell.self, forCellReuseIdentifier: ID)
@@ -66,7 +87,6 @@ class RecommendMajorCommentCell: UITableViewCell {
             make.top.equalTo(contentLabel.snp_bottom).offset(8)
             make.left.equalTo(titleLabel.snp_left)
             make.right.equalTo(contentLabel.snp_right)
-            make.height.equalTo(15)
             make.bottom.equalToSuperview().offset(-10)
         }
     }
@@ -105,4 +125,63 @@ class RecommendMajorCommentCell: UITableViewCell {
         return timeLabel
     }()
     
+    private lazy var collectionView: UICollectionView = {
+        let collectionView = UICollectionView.init(frame: CGRect.zero, collectionViewLayout: collectionViewLayout)
+        collectionView.backgroundColor = kf7f8faColor
+        collectionView.delegate = self;
+        collectionView.dataSource = self;
+        collectionView.showsVerticalScrollIndicator = false
+        collectionView.showsHorizontalScrollIndicator = false
+        collectionView.bounces = false
+        collectionView.isScrollEnabled = false
+        return collectionView
+    }()
+    
+    private lazy var collectionViewLayout: UICollectionViewFlowLayout = {
+        let collectionViewLayout = UICollectionViewLeftAlignedLayout.init()
+        collectionViewLayout.minimumLineSpacing = 0
+        collectionViewLayout.minimumInteritemSpacing =  0
+        collectionViewLayout.scrollDirection = UICollectionView.ScrollDirection.vertical
+        collectionViewLayout.estimatedItemSize = CGSize(width: kScreenWidth - 62, height: 50)
+        return collectionViewLayout
+    }()
+    
+    //加载数据
+    func reloadData() {
+        if subCommentCount != 0 {
+            //collectionView重新加载数据
+            self.collectionView.reloadData()
+            //更新collectionView的高度约束
+            let contentSize = self.collectionView.collectionViewLayout.collectionViewContentSize
+            collectionView.snp.remakeConstraints { (make) in
+                make.top.equalTo(timeLabel.snp_bottom).offset(10)
+                make.left.equalTo(contentLabel.snp_left)
+                make.right.equalTo(contentLabel.snp_right)
+                make.bottom.equalTo(-20)
+                make.height.equalTo(contentSize.height)
+            }
+            self.collectionView.collectionViewLayout.invalidateLayout()
+        }
+    }
+}
+
+extension RecommendMajorCommentCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
+    func numberOfSections(in collectionView: UICollectionView) -> Int {
+        return 1
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
+        return 2
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
+        let cell = RecommendSubCommentCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
+        
+        return cell
+    }
+    
+    func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
+        print("点击了collection--\(indexPath.row)")
+    }
+        
 }

+ 0 - 9
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/全部评论的Cell/RecommendSubCommentCell.swift

@@ -1,9 +0,0 @@
-//
-//  RecommendSubCommentCell.swift
-//  RainbowPlanet
-//
-//  Created by Christopher on 2019/6/14.
-//  Copyright © 2019 RainbowPlanet. All rights reserved.
-//  推荐图文内容--次级评论のCell
-
-import Foundation

+ 109 - 0
RainbowPlanet/RainbowPlanet/Modules/CommunityModule/CommunityRecommendDetail/View/全部评论的Cell/RecommendSubCommentCollectionCell.swift

@@ -0,0 +1,109 @@
+//
+//  RecommendSubCommentCollectionCell.swift
+//  RainbowPlanet
+//
+//  Created by Christopher on 2019/6/15.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//  推荐图文内容--次级评论のCell
+
+import UIKit
+
+class RecommendSubCommentCollectionCell: UICollectionViewCell {
+    
+    class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> RecommendSubCommentCollectionCell {
+        let ID = "RecommendSubCommentCollectionCell"
+        collectionView.register(RecommendSubCommentCollectionCell.self, forCellWithReuseIdentifier: ID)
+        let cell : RecommendSubCommentCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: ID, for: indexPath) as! RecommendSubCommentCollectionCell
+        cell.indexPath = indexPath
+        return cell
+    }
+    //MARK: - indexPath
+    var indexPath: IndexPath?{
+        didSet {
+            
+        }
+    }
+    //MARK: - 初始化
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+        backgroundColor = kffffffColor
+        setupViews()
+        setupLayouts()
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    //MRAK: - 设置View
+    private func setupViews() {
+        backgroundColor = kf7f8faColor
+        
+        addSubview(iconImageView)
+        addSubview(titleLabel)
+        addSubview(contentLabel)
+        addSubview(timeLabel)
+    }
+    
+    private func setupLayouts() {
+        iconImageView.snp.makeConstraints { (make) in
+            make.top.equalTo(10)
+            make.left.equalTo(10)
+            make.size.equalTo(24)
+        }
+        titleLabel.snp.makeConstraints { (make) in
+            make.left.equalTo(iconImageView.snp_right).offset(10)
+            make.right.equalToSuperview().offset(-10)
+            make.centerY.equalTo(iconImageView)
+            make.height.equalTo(17)
+        }
+        contentLabel.snp.makeConstraints { (make) in
+            make.top.equalTo(titleLabel.snp_bottom).offset(12)
+            make.left.equalTo(titleLabel.snp_left)
+            make.right.equalToSuperview().offset(-10)
+            make.width.equalTo(kScreenWidth-62-54)            
+        }
+        timeLabel.snp.makeConstraints { (make) in
+            make.top.equalTo(contentLabel.snp_bottom).offset(8)
+            make.left.equalTo(titleLabel.snp_left)
+            make.right.equalTo(contentLabel.snp_right)
+            make.height.equalTo(15)
+            make.bottom.equalToSuperview()
+        }
+    }
+    
+    lazy var iconImageView : UIImageView = {
+        let iconImageView = UIImageView()
+        iconImageView.image = kImage(name: "page05")
+        return iconImageView
+    }()
+    
+    private lazy var titleLabel: UILabel = {
+        let titleLabel = UILabel()
+        titleLabel.text = "Monster"
+        titleLabel.textColor = k999999Color
+        titleLabel.font = kRegularFont14
+        titleLabel.textAlignment = .left
+        return titleLabel
+    }()
+    
+    private lazy var contentLabel: UILabel = {
+        let contentLabel = UILabel()
+        contentLabel.text = "我也觉得好看"
+        contentLabel.textColor = k333333Color
+        contentLabel.font = kRegularFont14
+        contentLabel.textAlignment = .left
+        contentLabel.numberOfLines = 0
+        return contentLabel
+    }()
+    
+    private lazy var timeLabel: UILabel = {
+        let timeLabel = UILabel()
+        timeLabel.text = "6个小时前"
+        timeLabel.textColor = kbbbbbbColor
+        timeLabel.font = kRegularFont12
+        timeLabel.textAlignment = .left
+        return timeLabel
+    }()
+    
+}