Commit 694785a0d91f4891b519fa43b1f029faa80ebafa
1 parent
dc564c43
表情显示问题
Showing
3 changed files
with
50 additions
and
18 deletions
metaCode/Classes/Main/VideoPage/Controller/CNLiveShortVideoViewController.swift
| ... | ... | @@ -333,7 +333,7 @@ extension CNLiveShortVideoViewController { |
| 333 | 333 | } |
| 334 | 334 | func commentActionMethod(viewcell: CNLiveShortVideoListTableViewCell, button: UIButton) { |
| 335 | 335 | CNLiveShortVideoCommentListView.showVideoCommentListView(pid: viewcell.homeModel.pid, contentSid: viewcell.homeModel.icon!.id, result: { commentModel in |
| 336 | - | |
| 336 | + button.setTitle("\(commentModel)", for: .normal) | |
| 337 | 337 | }) |
| 338 | 338 | } |
| 339 | 339 | func shareActionMethod(viewcell: CNLiveShortVideoListTableViewCell, button: UIButton) { | ... | ... |
metaCode/Classes/Main/VideoPage/Model/CNLiveShortVideoHomeModel.swift
| ... | ... | @@ -26,9 +26,13 @@ class ShortVideoHomeCommentListModel: BaseModel { |
| 26 | 26 | super.didFinishMapping() |
| 27 | 27 | cell_h += comment.cellH |
| 28 | 28 | cell_h += 10 |
| 29 | + | |
| 29 | 30 | for replyModel in replyData.replys { |
| 30 | 31 | tableView_h += replyModel.cellH |
| 31 | 32 | } |
| 33 | + if replyData.total_hd ?? 0 > 2 { | |
| 34 | + cell_h += 30 | |
| 35 | + } | |
| 32 | 36 | cell_h += tableView_h |
| 33 | 37 | } |
| 34 | 38 | |
| ... | ... | @@ -60,23 +64,25 @@ class ShortVideoHomeCommentFListModel: BaseModel { |
| 60 | 64 | override func didFinishMapping() { |
| 61 | 65 | super.didFinishMapping() |
| 62 | 66 | |
| 63 | - let modifier = CNLiveShortVideoMateCodeLinePositionModifier(font: medium_adapt_font(pointSize: 16), paddingTop: 5, paddingBottom: 5, lineHeightMultiple: 2) | |
| 64 | - let comment = CNLiveBusinessTools.replaceQQemoji(withCustomText: self.content ?? "") | |
| 65 | - let attributes = NSMutableAttributedString(attributedString: comment) | |
| 66 | - attributes.addAttribute(NSAttributedString.Key.foregroundColor, value: HexColor("#333333")!, range: NSRange(location: 0, length: comment.length)) | |
| 67 | - attributes.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 16), range: NSRange(location: 0, length: comment.length)) | |
| 67 | + let modifier = CNLiveShortVideoMateCodeLinePositionModifier(font: medium_adapt_font(pointSize: 16), paddingTop: 0, paddingBottom: 0, lineHeightMultiple: 1.5) | |
| 68 | + let comment = NSMutableAttributedString.init(string: self.content ?? "") | |
| 69 | +// let comment = CNLiveBusinessTools.replaceQQemoji(withCustomText: self.content ?? "") | |
| 70 | + let temp_string = CNLiveShortVideoMateCodeLinePositionModifier.replaceEmotions(textAttributedString: comment, mainString: self.content ?? "") | |
| 71 | + let attributes = NSMutableAttributedString(attributedString: temp_string) | |
| 72 | + attributes.addAttribute(NSAttributedString.Key.foregroundColor, value: HexColor("#333333")!, range: NSRange(location: 0, length: temp_string.length)) | |
| 73 | + attributes.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 16), range: NSRange(location: 0, length: temp_string.length)) | |
| 68 | 74 | let textContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80, height: CGFloat(HUGE))) |
| 69 | 75 | textContainer.linePositionModifier = modifier; |
| 70 | 76 | let textLayout = YYTextLayout(container: textContainer, text: attributes) |
| 71 | 77 | self.textLayout = textLayout |
| 72 | 78 | self.cellH = 70 + (textLayout?.textBoundingRect.size.height ?? 0) |
| 73 | 79 | } |
| 74 | - | |
| 75 | 80 | } |
| 76 | 81 | //回复数据 |
| 77 | 82 | class ShortVideoHomeCommentRListModel: BaseModel { |
| 78 | 83 | var total_hd: Int? = 0 //总数 |
| 79 | 84 | var replys = [ShortVideoHomeCommentRListItemModel]() |
| 85 | + | |
| 80 | 86 | } |
| 81 | 87 | |
| 82 | 88 | class ShortVideoHomeCommentRListItemModel: BaseModel { |
| ... | ... | @@ -105,10 +111,12 @@ class ShortVideoHomeCommentRListItemModel: BaseModel { |
| 105 | 111 | super.didFinishMapping() |
| 106 | 112 | |
| 107 | 113 | let modifier = CNLiveShortVideoMateCodeLinePositionModifier(font: semibold_adapt_font(pointSize: 14), paddingTop: 0, paddingBottom: 0, lineHeightMultiple: 1.5) |
| 108 | - let comment = CNLiveBusinessTools.replaceQQemoji(withCustomText: content ?? "") | |
| 109 | - let attributes = NSMutableAttributedString(attributedString: comment) | |
| 110 | - attributes.addAttribute(NSAttributedString.Key.foregroundColor, value: HexColor("#333333")!, range: NSRange(location: 0, length: comment.length)) | |
| 111 | - attributes.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 16), range: NSRange(location: 0, length: comment.length)) | |
| 114 | + let comment = NSMutableAttributedString.init(string: self.content ?? "") | |
| 115 | +// let comment = CNLiveBusinessTools.replaceQQemoji(withCustomText: self.content ?? "") | |
| 116 | + let temp_string = CNLiveShortVideoMateCodeLinePositionModifier.replaceEmotions(textAttributedString: comment, mainString: self.content ?? "") | |
| 117 | + let attributes = NSMutableAttributedString(attributedString: temp_string) | |
| 118 | + attributes.addAttribute(NSAttributedString.Key.foregroundColor, value: HexColor("#333333")!, range: NSRange(location: 0, length: temp_string.length)) | |
| 119 | + attributes.addAttribute(NSAttributedString.Key.font, value: medium_adapt_font(pointSize: 16), range: NSRange(location: 0, length: temp_string.length)) | |
| 112 | 120 | let textContainer = YYTextContainer(size: CGSize(width: KSreenWidth-80-40, height: CGFloat(HUGE))) |
| 113 | 121 | textContainer.linePositionModifier = modifier; |
| 114 | 122 | let textLayout = YYTextLayout(container: textContainer, text: attributes) |
| ... | ... | @@ -169,4 +177,30 @@ class CNLiveShortVideoMateCodeLinePositionModifier: NSObject, YYTextLinePosition |
| 169 | 177 | let lineHeight = font.pointSize * lineHeightMultiple |
| 170 | 178 | return paddingTop + paddingBottom + ascent + descent + CGFloat(lineCount - 1) * lineHeight |
| 171 | 179 | } |
| 180 | + | |
| 181 | + static func replaceEmotions(textAttributedString: NSMutableAttributedString, mainString: String) -> NSMutableAttributedString { | |
| 182 | + do { | |
| 183 | + let regex = try NSRegularExpression(pattern: "\\[(.*?)\\]", options: .caseInsensitive) | |
| 184 | + | |
| 185 | + let matches = regex.matches(in: textAttributedString.string, options: [], range: NSRange(location: 0, length: textAttributedString.string.count)) | |
| 186 | + if !matches.isEmpty { | |
| 187 | + let emojiArr = CNLiveQQEmotionManager.emotionsForQQ() | |
| 188 | + for i in (0..<matches.count).reversed() { | |
| 189 | + let result = matches[i] | |
| 190 | + | |
| 191 | + for j in 0..<emojiArr.count { | |
| 192 | + if mainString.substring(with: Range(result.range, in: mainString)!) == emojiArr[j].displayName { | |
| 193 | + let attachText = NSAttributedString.yy_attachmentString(withContent: emojiArr[j].image, contentMode: .scaleAspectFit, attachmentSize: CGSize(width: adapt_length(length: 18), height: adapt_length(length: 18)), alignTo: semibold_adapt_font(pointSize: 16), alignment: .center) | |
| 194 | + | |
| 195 | + textAttributedString.replaceCharacters(in: result.range, with: attachText) | |
| 196 | + } | |
| 197 | + } | |
| 198 | + } | |
| 199 | + } | |
| 200 | + return textAttributedString | |
| 201 | + } catch { | |
| 202 | + print("Error creating NSRegularExpression: \(error.localizedDescription)") | |
| 203 | + return textAttributedString | |
| 204 | + } | |
| 205 | + } | |
| 172 | 206 | } | ... | ... |
metaCode/Classes/Main/VideoPage/View/CNLiveShortVideoCommentListView.swift
| ... | ... | @@ -121,6 +121,7 @@ class CNLiveShortVideoCommentListView: UIView, UITableViewDelegate, UITableViewD |
| 121 | 121 | self.dataArray.addObjects(from: listArray) |
| 122 | 122 | self.total_hd = (result as! ShortVideoHomeCommentModel).total_hd ?? 0 |
| 123 | 123 | self.titleLabel.text = "\(self.total_hd ?? 0)条评论" |
| 124 | + self.resultBlock(self.total_hd ?? 0) | |
| 124 | 125 | if self.tableView.mj_footer != nil { |
| 125 | 126 | self.tableView.mj_footer?.endRefreshing() |
| 126 | 127 | } |
| ... | ... | @@ -248,13 +249,10 @@ class CNLiveShortVideoCommentListView: UIView, UITableViewDelegate, UITableViewD |
| 248 | 249 | let commentView = CNLiveShortVideoCommentListView.init(frame: CGRect.zero, pid: pid, toSid: contentSid) |
| 249 | 250 | commentView.resultBlock = result |
| 250 | 251 | |
| 251 | -// let delegate = UIApplication.shared.delegate as! AppDelegate | |
| 252 | -// delegate.window?.addSubview(commentView) | |
| 253 | 252 | currentViewController()?.view.addSubview(commentView) |
| 254 | 253 | commentView.snp.makeConstraints { make in |
| 255 | 254 | make.edges.equalToSuperview() |
| 256 | 255 | } |
| 257 | -// delegate.window?.layoutIfNeeded() | |
| 258 | 256 | currentViewController()?.view.layoutIfNeeded() |
| 259 | 257 | commentView.alpha = 0 |
| 260 | 258 | UIView.animate(withDuration: 0.1) { |
| ... | ... | @@ -313,10 +311,10 @@ extension CNLiveShortVideoCommentListView { |
| 313 | 311 | let model: ShortVideoHomeCommentListModel = dataArray[indexPath.row] as! ShortVideoHomeCommentListModel |
| 314 | 312 | return model.cell_h |
| 315 | 313 | } |
| 316 | - func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
| 317 | - let model: ShortVideoHomeCommentFListModel = ((dataArray[indexPath.row] as! ShortVideoHomeCommentListModel).comment) | |
| 318 | - self.resultBlock(model) | |
| 319 | - } | |
| 314 | +// func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { | |
| 315 | +// let model: ShortVideoHomeCommentFListModel = ((dataArray[indexPath.row] as! ShortVideoHomeCommentListModel).comment) | |
| 316 | +// self.resultBlock(model) | |
| 317 | +// } | |
| 320 | 318 | func image(forEmptyDataSet scrollView: UIScrollView) -> UIImage? { |
| 321 | 319 | return UIImage(named: "short_video_comment_empty") |
| 322 | 320 | } | ... | ... |