|
@@ -7,28 +7,14 @@
|
|
// 推荐图文内容--主评论のCell
|
|
// 推荐图文内容--主评论のCell
|
|
|
|
|
|
import UIKit
|
|
import UIKit
|
|
|
|
+import RxSwift
|
|
|
|
|
|
class RecommendMajorCommentCell: UITableViewCell {
|
|
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)
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
|
|
+ let disposeBag = DisposeBag()
|
|
|
|
+
|
|
|
|
+ /// 相关推荐高度
|
|
|
|
+ var heightModel1 = HeightModel()
|
|
|
|
|
|
class func cellWith(tableView:UITableView,indexPath:IndexPath) -> RecommendMajorCommentCell {
|
|
class func cellWith(tableView:UITableView,indexPath:IndexPath) -> RecommendMajorCommentCell {
|
|
let ID = "RecommendMajorCommentCell"
|
|
let ID = "RecommendMajorCommentCell"
|
|
@@ -59,46 +45,58 @@ class RecommendMajorCommentCell: UITableViewCell {
|
|
self.selectionStyle = .none
|
|
self.selectionStyle = .none
|
|
backgroundColor = kffffffColor
|
|
backgroundColor = kffffffColor
|
|
|
|
|
|
- addSubview(iconImageView)
|
|
|
|
|
|
+ addSubview(iconButton)
|
|
addSubview(titleLabel)
|
|
addSubview(titleLabel)
|
|
addSubview(contentLabel)
|
|
addSubview(contentLabel)
|
|
addSubview(timeLabel)
|
|
addSubview(timeLabel)
|
|
|
|
+ addSubview(tableView)
|
|
}
|
|
}
|
|
|
|
|
|
private func setupLayouts() {
|
|
private func setupLayouts() {
|
|
- iconImageView.snp.makeConstraints { (make) in
|
|
|
|
- make.top.equalTo(10)
|
|
|
|
|
|
+ iconButton.snp.makeConstraints { (make) in
|
|
|
|
+ make.top.equalTo(0)
|
|
make.left.equalTo(14)
|
|
make.left.equalTo(14)
|
|
make.size.equalTo(24)
|
|
make.size.equalTo(24)
|
|
}
|
|
}
|
|
titleLabel.snp.makeConstraints { (make) in
|
|
titleLabel.snp.makeConstraints { (make) in
|
|
- make.left.equalTo(iconImageView.snp_right).offset(10)
|
|
|
|
|
|
+ make.left.equalTo(iconButton.snp_right).offset(10)
|
|
make.right.equalToSuperview().offset(-26)
|
|
make.right.equalToSuperview().offset(-26)
|
|
- make.centerY.equalTo(iconImageView)
|
|
|
|
|
|
+ make.centerY.equalTo(iconButton)
|
|
make.height.equalTo(17)
|
|
make.height.equalTo(17)
|
|
}
|
|
}
|
|
|
|
+
|
|
contentLabel.snp.makeConstraints { (make) in
|
|
contentLabel.snp.makeConstraints { (make) in
|
|
- make.top.equalTo(titleLabel.snp_bottom).offset(10)
|
|
|
|
- make.left.equalTo(titleLabel.snp_left)
|
|
|
|
|
|
+ make.top.equalTo(iconButton.snp_bottom).offset(6)
|
|
|
|
+ make.left.equalTo(48)
|
|
make.right.equalToSuperview().offset(-14)
|
|
make.right.equalToSuperview().offset(-14)
|
|
}
|
|
}
|
|
timeLabel.snp.makeConstraints { (make) in
|
|
timeLabel.snp.makeConstraints { (make) in
|
|
make.top.equalTo(contentLabel.snp_bottom).offset(8)
|
|
make.top.equalTo(contentLabel.snp_bottom).offset(8)
|
|
make.left.equalTo(titleLabel.snp_left)
|
|
make.left.equalTo(titleLabel.snp_left)
|
|
make.right.equalTo(contentLabel.snp_right)
|
|
make.right.equalTo(contentLabel.snp_right)
|
|
- make.bottom.equalToSuperview().offset(-10)
|
|
|
|
|
|
+ make.height.equalTo(15)
|
|
|
|
+ }
|
|
|
|
+ tableView.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.height.equalTo(20)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- lazy var iconImageView : UIImageView = {
|
|
|
|
- let iconImageView = UIImageView()
|
|
|
|
- iconImageView.image = kImage(name: "page05")
|
|
|
|
- return iconImageView
|
|
|
|
|
|
+ private lazy var iconButton : UIButton = {
|
|
|
|
+ let iconButton = UIButton(type: UIButton.ButtonType.custom)
|
|
|
|
+ iconButton.setImage(kImage(name: "default_avatar"), for: UIControl.State.normal)
|
|
|
|
+ iconButton.cornerRadius = 12
|
|
|
|
+ iconButton.masksToBounds = true
|
|
|
|
+ iconButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
|
+
|
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
|
+ return iconButton
|
|
}()
|
|
}()
|
|
|
|
|
|
private lazy var titleLabel: UILabel = {
|
|
private lazy var titleLabel: UILabel = {
|
|
let titleLabel = UILabel()
|
|
let titleLabel = UILabel()
|
|
- titleLabel.text = "张吃饭"
|
|
|
|
titleLabel.textColor = k999999Color
|
|
titleLabel.textColor = k999999Color
|
|
titleLabel.font = kRegularFont14
|
|
titleLabel.font = kRegularFont14
|
|
titleLabel.textAlignment = .left
|
|
titleLabel.textAlignment = .left
|
|
@@ -107,7 +105,6 @@ class RecommendMajorCommentCell: UITableViewCell {
|
|
|
|
|
|
private lazy var contentLabel: UILabel = {
|
|
private lazy var contentLabel: UILabel = {
|
|
let contentLabel = UILabel()
|
|
let contentLabel = UILabel()
|
|
- contentLabel.text = "点击单条评时弹出选择操作框(目前仅支持回复),点击操作框后进行相应的操作"
|
|
|
|
contentLabel.textColor = k333333Color
|
|
contentLabel.textColor = k333333Color
|
|
contentLabel.font = kRegularFont14
|
|
contentLabel.font = kRegularFont14
|
|
contentLabel.textAlignment = .left
|
|
contentLabel.textAlignment = .left
|
|
@@ -117,87 +114,127 @@ class RecommendMajorCommentCell: UITableViewCell {
|
|
|
|
|
|
private lazy var timeLabel: UILabel = {
|
|
private lazy var timeLabel: UILabel = {
|
|
let timeLabel = UILabel()
|
|
let timeLabel = UILabel()
|
|
- timeLabel.text = "6个小时前"
|
|
|
|
timeLabel.textColor = kbbbbbbColor
|
|
timeLabel.textColor = kbbbbbbColor
|
|
timeLabel.font = kRegularFont12
|
|
timeLabel.font = kRegularFont12
|
|
timeLabel.textAlignment = .left
|
|
timeLabel.textAlignment = .left
|
|
return timeLabel
|
|
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
|
|
|
|
|
|
+ lazy var tableView: UITableView = {
|
|
|
|
+ let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
|
|
|
|
+ tableView.separatorStyle = .none
|
|
|
|
+ tableView.backgroundColor = kf7f8faColor
|
|
|
|
+ tableView.dataSource = self
|
|
|
|
+ tableView.delegate = self
|
|
|
|
+ tableView.estimatedSectionFooterHeight = 0
|
|
|
|
+ tableView.estimatedSectionHeaderHeight = 0
|
|
|
|
+ tableView.estimatedRowHeight = 0
|
|
|
|
+ tableView.isScrollEnabled = false
|
|
|
|
+ tableView.cornerRadius = 4
|
|
|
|
+ tableView.masksToBounds = true
|
|
|
|
+ return tableView
|
|
}()
|
|
}()
|
|
-
|
|
|
|
- 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
|
|
|
|
- }()
|
|
|
|
-
|
|
|
|
|
|
+ var tableViewHeight : CGFloat?
|
|
|
|
+
|
|
//加载数据
|
|
//加载数据
|
|
func reloadData() {
|
|
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()
|
|
|
|
|
|
+ //collectionView重新加载数据
|
|
|
|
+ self.tableView.reloadData()
|
|
|
|
+ //更新collectionView的高度约束
|
|
|
|
+ let contentSize = self.tableView.contentSize
|
|
|
|
+ tableViewHeight = contentSize.height
|
|
|
|
+ tableView.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.height.equalTo(contentSize.height)
|
|
|
|
+ }
|
|
|
|
+ let contentLabelHeight = communityPostCommentModel?.content?.heightForComment(font: kRegularFont14!, width: kScreenWidth - 14 - 48)
|
|
|
|
+ if communityPostCommentModel?.reply?.isEmpty ?? true {
|
|
|
|
+ let subViewHeight = 24.0 + (contentLabelHeight ?? 0) + 15.0
|
|
|
|
+ let spacHeight = 6.0 + 8.0 + 20.0
|
|
|
|
+ communityPostCommentModel?.height = CGFloat(subViewHeight) + CGFloat(spacHeight)
|
|
|
|
+ }else {
|
|
|
|
+ let autoHeight = (contentLabelHeight ?? 0) + (tableViewHeight ?? 0)
|
|
|
|
+ let subViewHeight = 24.0 + autoHeight + 15.0
|
|
|
|
+ let spacHeight = 6.0 + 8.0 + 10.0 + 20.0
|
|
|
|
+ communityPostCommentModel?.height = CGFloat(subViewHeight) + CGFloat(spacHeight)
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ var communityPostCommentModel : CommunityPostCommentModel? {
|
|
|
|
+ didSet {
|
|
|
|
+ iconButton.kf.setImage(with: kURLImage(name: communityPostCommentModel?.avatar ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar"))
|
|
|
|
+ titleLabel.text = communityPostCommentModel?.username
|
|
|
|
+ contentLabel.text = communityPostCommentModel?.content
|
|
|
|
+ timeLabel.text = communityPostCommentModel?.createdAt
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
-extension RecommendMajorCommentCell: UICollectionViewDelegateFlowLayout,UICollectionViewDataSource {
|
|
|
|
- func numberOfSections(in collectionView: UICollectionView) -> Int {
|
|
|
|
|
|
+
|
|
|
|
+// MARK: - tableView dataSource && delegate
|
|
|
|
+extension RecommendMajorCommentCell: UITableViewDataSource, UITableViewDelegate {
|
|
|
|
+
|
|
|
|
+ func numberOfSections(in tableView: UITableView) -> Int {
|
|
return 1
|
|
return 1
|
|
}
|
|
}
|
|
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
|
|
|
|
- return 2
|
|
|
|
|
|
+ func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
|
|
|
|
+ let reply = communityPostCommentModel?.reply?.prefix(2)
|
|
|
|
+ return reply?.count ?? 0
|
|
}
|
|
}
|
|
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
|
|
|
|
- let cell = RecommendSubCommentCollectionCell.cellWith(collectionView: collectionView, indexPath: indexPath)
|
|
|
|
|
|
+ func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
|
|
|
|
+
|
|
|
|
+ let reply = communityPostCommentModel?.reply?.prefix(2)
|
|
|
|
+ let cell = RecommendSubCommentTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
|
|
|
|
+ cell.communityPostReplyModel = reply?[indexPath.row]
|
|
return cell
|
|
return cell
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
|
|
|
|
- print("点击了collection--\(indexPath.row)")
|
|
|
|
|
|
+ func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize {
|
|
|
|
- return CGSize(width:kScreenWidth - 62, height: 50)
|
|
|
|
|
|
+ func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
|
|
|
|
+ let reply = communityPostCommentModel?.reply?.prefix(2)
|
|
|
|
+ return reply?[indexPath.row].height ?? 0
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
|
|
|
|
+ return 0.000001
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView {
|
|
|
|
- if kind == UICollectionView.elementKindSectionFooter {
|
|
|
|
- let footerView = RecommendSubCommentCollectionFooter.footerWith(collectionView: collectionView, kind: UICollectionView.elementKindSectionFooter, indexPath: indexPath)
|
|
|
|
- return footerView
|
|
|
|
|
|
+ func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
|
|
|
|
+ return UIView()
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
|
|
|
|
+ if communityPostCommentModel?.reply?.isEmpty ?? true {
|
|
|
|
+ return 0.000001
|
|
}else {
|
|
}else {
|
|
- return UICollectionReusableView()
|
|
|
|
- }
|
|
|
|
|
|
+ if communityPostCommentModel?.reply?.count ?? 0 > 2 {
|
|
|
|
+ return 30
|
|
|
|
+ }else {
|
|
|
|
+ return 10
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
- // 返回FooterView的宽高
|
|
|
|
- func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForFooterInSection section: Int) -> CGSize {
|
|
|
|
- return CGSize(width:kScreenWidth - 62, height: 40)
|
|
|
|
|
|
+ func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
|
|
|
|
+ if communityPostCommentModel?.reply?.count ?? 0 > 2 {
|
|
|
|
+ let footer = RecommendSubCommentTableViewFooter(frame: CGRect(x: 0, y: 0, width: kScreenWidth-48-14, height: 30))
|
|
|
|
+ footer.communityPostCommentModel = communityPostCommentModel
|
|
|
|
+ return footer
|
|
|
|
+ }else {
|
|
|
|
+ return UIView()
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
+
|