Commit efa9d3fa69b9fe5c79fba63f5bd73c56bf37e0f0

Authored by liushiyu
1 parent f9f0c0ca

回复相关问题修改

metaCode/Classes/Main/VideoPage/Model/CNLiveShortVideoHomeModel.swift
... ... @@ -26,19 +26,16 @@ class ShortVideoHomeCommentListModel: BaseModel {
26 26 override func didFinishMapping() {
27 27 super.didFinishMapping()
28 28 cell_h += comment.cellH
29   - cell_h += 10
30 29  
31 30 for replyModel in replyData.replys {
32 31 tableView_h += replyModel.cellH
33 32 }
34 33 if replyData.replyCount ?? 0 > 2 {
35   - print("回复数=>\(replyData.replyCount ?? 0)")
36 34 tableView_top += 30.0
37 35 cell_h += 30
38 36 }
39 37 cell_h += tableView_h
40 38 }
41   -
42 39 }
43 40 //评论数据
44 41 class ShortVideoHomeCommentFListModel: BaseModel {
... ... @@ -62,7 +59,8 @@ class ShortVideoHomeCommentFListModel: BaseModel {
62 59  
63 60 var iconSize: CGSize = CGSize(width: 50, height: 50)
64 61 var textLayout: YYTextLayout!
65   - var cellH: CGFloat! = 0
  62 + var nickLayout: YYTextLayout!
  63 + var cellH: CGFloat! = 50.0
66 64  
67 65 override func didFinishMapping() {
68 66 super.didFinishMapping()
... ... @@ -78,7 +76,15 @@ class ShortVideoHomeCommentFListModel: BaseModel {
78 76 textContainer.linePositionModifier = modifier;
79 77 let textLayout = YYTextLayout(container: textContainer, text: attributes)
80 78 self.textLayout = textLayout
81   - self.cellH = 70 + (textLayout?.textBoundingRect.size.height ?? 0)
  79 + self.cellH += (textLayout?.textBoundingRect.size.height ?? 0)
  80 +
  81 + let textAttributedString = NSMutableAttributedString.init(string: self.nick ?? "")
  82 + textAttributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: HexColor("#AFAFAF")!, range: NSRange(location: 0, length: textAttributedString.length))
  83 + textAttributedString.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 12), range: NSRange(location: 0, length: textAttributedString.length))
  84 + let nickContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80, height: 20))
  85 + nickContainer.linePositionModifier = modifier;
  86 + self.nickLayout = YYTextLayout(container: nickContainer, text: textAttributedString)
  87 + self.cellH += (self.nickLayout?.textBoundingRect.size.height ?? 0)
82 88 }
83 89 }
84 90 //回复数据
... ... @@ -108,7 +114,8 @@ class ShortVideoHomeCommentRListItemModel: BaseModel {
108 114 var icon: String? = ""
109 115  
110 116 var textLayout: YYTextLayout!
111   - var cellH: CGFloat! = 0
  117 + var nickLayout: YYTextLayout!
  118 + var cellH: CGFloat! = 50.0
112 119  
113 120 override func didFinishMapping() {
114 121 super.didFinishMapping()
... ... @@ -122,9 +129,18 @@ class ShortVideoHomeCommentRListItemModel: BaseModel {
122 129 attributes.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 16), range: NSRange(location: 0, length: temp_string.length))
123 130 let textContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80-40, height: CGFloat(HUGE)))
124 131 textContainer.linePositionModifier = modifier;
125   - let textLayout = YYTextLayout(container: textContainer, text: attributes)
126   - self.textLayout = textLayout
127   - self.cellH = 70 + (textLayout?.textBoundingRect.size.height ?? 0)
  132 + self.textLayout = YYTextLayout(container: textContainer, text: attributes)
  133 + self.cellH += (self.textLayout?.textBoundingRect.size.height ?? 0)
  134 +
  135 + let textAttributedString = NSMutableAttributedString.init(string: "\(self.fromNick ?? "") ?? \(self.toNick ?? "")")
  136 + textAttributedString.addAttribute(NSAttributedString.Key.foregroundColor, value: HexColor("#AFAFAF")!, range: NSRange(location: 0, length: textAttributedString.length))
  137 + textAttributedString.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 12), range: NSRange(location: 0, length: textAttributedString.length))
  138 + let attachText = NSAttributedString.yy_attachmentString(withContent: UIImage(named: "short_video_reply_name"), contentMode: .scaleAspectFill, attachmentSize: CGSize(width: adapt_length(length: 8), height: adapt_length(length: 8)), alignTo: medium_adapt_font(pointSize: 12), alignment: .center)
  139 + textAttributedString.replaceCharacters(in: NSRange(location: self.fromNick!.count + 2, length: 2), with: attachText)
  140 + let nickContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80-40, height: 20))
  141 + nickContainer.linePositionModifier = modifier;
  142 + self.nickLayout = YYTextLayout(container: nickContainer, text: textAttributedString)
  143 + self.cellH += (self.nickLayout?.textBoundingRect.size.height ?? 0)
128 144 }
129 145 }
130 146  
... ...
metaCode/Classes/Main/VideoPage/View/CNLiveShortVideoCommentListView.swift
... ... @@ -218,7 +218,7 @@ class CNLiveShortVideoCommentListView: UIView, UITableViewDelegate, UITableViewD
218 218 contentView.addSubview(tableView)
219 219 tableView.snp.makeConstraints { make in
220 220 make.left.right.equalToSuperview()
221   - make.top.equalTo(lineLabel.snp.bottom).offset(10)
  221 + make.top.equalTo(lineLabel.snp.bottom)
222 222 make.bottom.equalTo(sendButton.snp.top).offset(-5)
223 223 }
224 224 }
... ... @@ -356,12 +356,19 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
356 356 return imageView
357 357 }()
358 358  
359   - lazy var titleLabel: UILabel = {
360   - let titleLabel = UILabel.init()
  359 + lazy var titleLabel: YYLabel = {
  360 + let titleLabel = YYLabel()
361 361 titleLabel.textColor = HexColor("#AFAFAF")
362 362 titleLabel.lineBreakMode = .byTruncatingTail
363 363 titleLabel.numberOfLines = 2
364 364 titleLabel.font = medium_adapt_font(pointSize: 12)
  365 + titleLabel.displaysAsynchronously = true
  366 + titleLabel.clearContentsBeforeAsynchronouslyDisplay = false
  367 + titleLabel.fadeOnAsynchronouslyDisplay = false
  368 + titleLabel.textAlignment = .left
  369 + titleLabel.textVerticalAlignment = .center
  370 + titleLabel.textContainerInset = UIEdgeInsets.zero
  371 + titleLabel.isUserInteractionEnabled = true
365 372 return titleLabel
366 373 }()
367 374  
... ... @@ -483,7 +490,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
483 490 make.left.equalTo(iconView.snp.right).offset(10)
484 491 make.top.equalToSuperview().offset(10)
485 492 make.right.equalToSuperview().offset(-10)
486   - make.height.equalTo(20)
  493 + make.height.equalTo(1)
487 494 }
488 495 contentView.addSubview(owerView)
489 496 owerView.snp.makeConstraints { make in
... ... @@ -495,7 +502,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
495 502 make.top.equalTo(titleLabel.snp.bottom).offset(10)
496 503 make.left.equalTo(titleLabel.snp.left)
497 504 make.right.equalToSuperview().offset(-10)
498   - make.height.equalTo(20)
  505 + make.height.equalTo(1)
499 506 }
500 507 contentView.addSubview(likeButton)
501 508 likeButton.snp.makeConstraints { make in
... ... @@ -519,9 +526,9 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
519 526 }
520 527 contentView.addSubview(replyUnfoldButton)
521 528 replyUnfoldButton.snp.makeConstraints { make in
522   - make.top.equalTo(timeLabel.snp.bottom).offset(5)
  529 + make.top.equalTo(timeLabel.snp.bottom)
523 530 make.left.equalTo(titleLabel.snp.left)
524   - make.height.equalTo(20)
  531 + make.height.equalTo(30)
525 532 }
526 533 contentView.addSubview(tableView)
527 534 }
... ... @@ -535,8 +542,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
535 542 indexPath_current = indexPath
536 543 commentModel = commentData
537 544 iconView.kf.indicatorType = .activity
538   - iconView.kf.setImage(with: URL(string: commentData.icon!), placeholder: UIImage(named: "short_video_default"))
539   - titleLabel.text = commentData.nick
  545 + iconView.kf.setImage(with: URL(string: commentData.facepath!), placeholder: UIImage(named: "short_video_default"))
540 546 likeButton.isSelected = commentData.isPraised!
541 547 likeButton.setTitle("\(commentData.praiseCount ?? 0)", for: .normal)
542 548 timeLabel.text = commentData.created_at
... ... @@ -561,13 +567,20 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
561 567 make.right.equalToSuperview().offset(-10)
562 568 make.height.equalTo(commentData.textLayout.textBoundingRect.size.height)
563 569 }
  570 + self.titleLabel.textLayout = commentData.nickLayout
  571 + self.titleLabel.snp.remakeConstraints { make in
  572 + make.left.equalTo(self.iconView.snp.right).offset(10)
  573 + make.top.equalToSuperview().offset(10)
  574 + make.right.equalToSuperview().offset(-10)
  575 + make.height.equalTo(commentData.nickLayout.textBoundingRect.size.height)
  576 + }
564 577 self.tableView.removeFromSuperview()
565 578 if replyData.replyCount ?? 0 > 2 {
566 579 self.contentView.addSubview(self.tableView)
567 580 self.tableView.snp.makeConstraints { make in
568 581 make.left.equalToSuperview().offset(60)
569 582 make.right.equalToSuperview().offset(-10)
570   - make.top.equalTo(self.timeLabel.snp.bottom).offset(10+tableView_top)
  583 + make.top.equalTo(self.timeLabel.snp.bottom).offset(tableView_top)
571 584 make.height.equalTo(self.tableView_height)
572 585 }
573 586 self.tableView.reloadData()
... ... @@ -580,7 +593,7 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
580 593 commentModel = commentData
581 594 iconView.kf.indicatorType = .activity
582 595 iconView.kf.setImage(with: URL(string: replyModel.fromFace!), placeholder: UIImage(named: "short_video_default"))
583   - titleLabel.text = replyModel.fromNick
  596 + titleLabel.textLayout = replyModel.nickLayout
584 597 likeButton.isSelected = replyModel.isPraised!
585 598 likeButton.setTitle("\(replyModel.praiseCount ?? 0)", for: .normal)
586 599 timeLabel.text = replyModel.created_at
... ... @@ -598,6 +611,13 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
598 611 make.right.equalToSuperview().offset(-10)
599 612 make.height.equalTo(replyModel.textLayout.textBoundingRect.size.height)
600 613 }
  614 + self.titleLabel.textLayout = replyModel.nickLayout
  615 + self.titleLabel.snp.remakeConstraints { make in
  616 + make.left.equalTo(self.iconView.snp.right).offset(10)
  617 + make.top.equalToSuperview().offset(10)
  618 + make.right.equalToSuperview().offset(-10)
  619 + make.height.equalTo(replyModel.nickLayout.textBoundingRect.size.height)
  620 + }
601 621 }
602 622 }
603 623  
... ... @@ -695,11 +715,15 @@ class CNLiveShortVideoCommentListTableViewCell: UITableViewCell , UITableViewDel
695 715  
696 716 @objc func replyUnfoldMethod(button: UIButton) {
697 717 showLoading(message: "")
  718 + print("这里点击的时候走了多少次")
698 719 let replyModel: ShortVideoHomeCommentRListItemModel = self.dataSource.lastObject as! ShortVideoHomeCommentRListItemModel
699 720 CNLiveShortVideoViewModel.requestcommentWithReplyList(commentId: commentModel.commentId!, seqId: replyModel.seqId!) {[weak self] result, respStatue in
700 721 guard let self = self else { return }
701 722 if respStatue == .success {
702 723 let tempArray = result as! [ShortVideoHomeCommentRListItemModel]
  724 + if tempArray.count == 0 {
  725 + return
  726 + }
703 727 let dataArray_temp = NSMutableArray(array: self.dataSource)
704 728 self.dataSource.removeAllObjects()
705 729 var cell_h: CGFloat = 0.0
... ...
metaCode/Classes/Main/VideoPage/ViewModel/CNLiveShortVideoViewModel.swift
... ... @@ -407,8 +407,9 @@ class CNLiveShortVideoViewModel: NSObject {
407 407 tempArray.add(listModel)
408 408 }
409 409 reultShortVideoBlock(tempArray, .success)
  410 + } else {
  411 + reultShortVideoBlock(Array<Any>(), .success)
410 412 }
411   - reultShortVideoBlock(Array<Any>(), .success)
412 413 }
413 414 } else {
414 415 showMessage(message: resp["errorMessage"] as! String)
... ...