// // CommunityRecommendController.swift // RainbowPlanet // // Created by 南鑫林 on 2019/6/13. // Copyright © 2019 RainbowPlanet. All rights reserved. // import UIKit class CommunityRecommendController: BaseViewController { deinit { if observe != nil { NotificationCenter.default.removeObserver(observe!) } } weak var observe : NSObjectProtocol? // 帖子Id var id : Int = 0 var communityPostDetailModel : CommunityPostDetailModel? // 评论 var communityPostCommentsModel : CommunityPostCommentsModel? var communityPostCommentModels = Array() var communityPostCommentModel : CommunityPostCommentModel? var keyBoardCommentView : KeyBoardCommentView? // 相关推荐 var communityPostDataModels = Array() // 全部评论 var count : Int = 0 var indexPath : IndexPath? var heights = Array() /// 相关推荐高度 var heightModel = HeightModel() /// 内容高度 var heightModel1 = HeightModel() /// 最后滚动的位置 var lastContentOffset : CGFloat = 0 override func viewDidLoad() { super.viewDidLoad() setupViews() setupLayouts() setupData() } override func setupViews() { view.backgroundColor = kf7f8faColor navigationBar.addSubview(avatarButton) navigationBar.addSubview(nameButton) navigationBar.addSubview(followButton) navigationBar.wr_setRightButton(image: kImage(name: "nav_share_black")!) view.addSubview(commentView) view.addSubview(tableView) view.addSubview(sharedButton) } override func setupLayouts() { avatarButton.snp.makeConstraints { (make) in make.left.equalTo(navigationBar.leftButton.snp_right) make.size.equalTo(30) make.centerY.equalTo(navigationBar.leftButton) } nameButton.snp.makeConstraints { (make) in make.centerY.equalTo(avatarButton) make.left.equalTo(avatarButton.snp_right).offset(4) } followButton.snp_makeConstraints { (make) in make.right.equalTo(navigationBar.rightButton.snp_left) make.height.equalTo(24) make.width.equalTo(60) make.centerY.equalTo(navigationBar.leftButton) } commentView.snp.makeConstraints { (make) in make.left.right.equalToSuperview() make.height.equalTo(48+kSafeTabBarHeight) make.bottom.equalToSuperview() } tableView.snp.makeConstraints { (make) in make.top.equalToSuperview().offset(kNavBarTotalHeight) make.left.right.equalToSuperview() make.bottom.equalTo(commentView.snp_top).offset(0) } sharedButton.snp.makeConstraints { (make) in make.bottom.equalTo(commentView.snp_top).offset(-20) make.height.equalTo(71) make.width.equalTo(78) make.right.equalTo(-14) } } lazy var avatarButton: UIButton = { let avatarButton = UIButton(type: UIButton.ButtonType.custom) avatarButton.setImage(kImage(name: "default_avatar"), for: UIControl.State.normal) avatarButton.cornerRadius = 15 avatarButton.masksToBounds = true return avatarButton }() lazy var nameButton: UIButton = { let nameButton = UIButton(type: UIButton.ButtonType.custom) nameButton.setTitle("昵称", for: UIControl.State.normal) nameButton.setTitleColor(k262626Color, for: UIControl.State.normal) nameButton.titleLabel?.font = kRegularFont14 return nameButton }() lazy var followButton: UIButton = { let followButton = UIButton(type: UIButton.ButtonType.custom) followButton.titleLabel?.font = kMediumFont13 followButton.cornerRadius = 12 followButton.masksToBounds = true followButton.layer.borderWidth = 0.5 followButton.isHidden = true return followButton }() 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 return tableView }() lazy var communityPostDetailTableViewHeaderView: CommunityPostDetailTableViewHeaderView = { let communityPostDetailTableViewHeaderView = CommunityPostDetailTableViewHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 0)) return communityPostDetailTableViewHeaderView }() lazy var commentView: RecommendBottomCommentView = { let commentView = RecommendBottomCommentView() return commentView }() lazy var sharedButton: UIButton = { let sharedButton = UIButton(type: UIButton.ButtonType.custom) sharedButton.setImage(kImage(name: "share_pic_poster_floating"), for: UIControl.State.normal) return sharedButton }() override func setupData() { //头像 avatarButton.rx.tap.subscribe(onNext: { [weak self] (data) in if self?.communityPostDetailModel?.uid != UserModel.shared().getModel()?.uid { let vc = OtherPersonalCenterViewController() vc.uid = self?.communityPostDetailModel?.uid ?? 0 self?.navigationController?.pushViewController(vc, animated: true) } }).disposed(by: disposeBag) //用户昵称 nameButton.rx.tap.subscribe(onNext: { [weak self] (data) in if self?.communityPostDetailModel?.uid != UserModel.shared().getModel()?.uid { let vc = OtherPersonalCenterViewController() vc.uid = self?.communityPostDetailModel?.uid ?? 0 self?.navigationController?.pushViewController(vc, animated: true) } }).disposed(by: disposeBag) // 关注 followButton.rx.tap.subscribe(onNext: { [weak self] (data) in CommunityFollowUserViewModel.shared.follow(communityPostDetailModel: (self?.communityPostDetailModel)!, button: (self?.followButton)!) }).disposed(by: disposeBag) //分享 navigationBar.onClickRightButton = { [weak self] in self?.share() } sharedButton.rx.tap.subscribe(onNext: { [weak self] _ in self?.share() }).disposed(by: disposeBag) tableView.addHeaderWithHeader(withBeginRefresh: true, animation: false) { [weak self] (page) in self?.communityPostDetailApi() self?.communityPostCommentApi(page: page) } tableView.addFooterWithWithHeader(withAutomaticallyRefresh: true) { [weak self] (page) in self?.communityPostsApi(page: page) } commentView.bottomClickClosure = { [weak self] (clickType) in switch clickType { case BottomClickType.typeComment: self?.showKeyBoardCommentView(placeholder: "添加评论...") self?.hiddenKeyBoardCommentView() case BottomClickType.typeLike: VirusViewModel.shared.virueRecordAddApiPraise(communityPostDetailModel: self?.communityPostDetailModel,commentView: (self?.commentView)!) case BottomClickType.typeCollect: VirusViewModel.shared.virueRecordAddApiCollection(communityPostDetailModel: self?.communityPostDetailModel,commentView: (self?.commentView)!) } } observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("followApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in let followStatusModel = notification.object as? FollowStatusModel if self?.communityPostDetailModel?.uid == followStatusModel?.uid { self?.communityPostDetailModel?.isFollow = followStatusModel?.isFollowStatus self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel CommunityFollowUserViewModel.shared.setFollowType(followButton: (self?.followButton)!, followType: FollowType(rawValue: self?.communityPostDetailModel?.isFollow ?? 0) ?? .futureFollow) self?.tableView.reloadData() } } observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("unlikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in let followStatusModel = notification.object as? FollowStatusModel if self?.communityPostDetailModel?.id == followStatusModel?.postId { self?.communityPostDetailModel?.isDislike = followStatusModel?.isFollowStatus self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel self?.tableView.reloadData() } } observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("islikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in let followStatusModel = notification.object as? FollowStatusModel if self?.communityPostDetailModel?.id == followStatusModel?.postId { self?.communityPostDetailModel?.isDislike = followStatusModel?.isFollowStatus self?.commentView.communityPostDetailModel = self?.communityPostDetailModel } if !(self?.communityPostCommentModels.isEmpty ?? true) { for communityPostDataModel in (self?.communityPostDataModels)! { if communityPostDataModel.uid == followStatusModel?.uid { communityPostDataModel.isLike = followStatusModel?.isFollowStatus } } } self?.tableView.reloadData() } observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("isCollectApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in let followStatusModel = notification.object as? FollowStatusModel if self?.communityPostDetailModel?.id == followStatusModel?.postId { self?.communityPostDetailModel?.isCollect = followStatusModel?.isFollowStatus self?.commentView.communityPostDetailModel = self?.communityPostDetailModel self?.tableView.reloadData() } self?.tableView.reloadData() } } /// 显示键盘 func showKeyBoardCommentView(placeholder:String) { keyBoardCommentView = KeyBoardCommentView.keyBoardCommentView(placeholder:placeholder,sendClosure: { [weak self] text in self?.communityPostCommentApi(text: text, complete: { self?.keyBoardCommentView?.dismisskeyBoardCommentView() }) }) } /// 隐藏键盘 func hiddenKeyBoardCommentView() { keyBoardCommentView?.hiddenViewClosure = { [weak self] in self?.communityPostCommentModel = nil } } /// 分享 func share() { var title = self.communityPostDetailModel?.title?.prefix(12) if title == nil || title == "" { title = self.communityPostDetailModel?.content?.prefix(12) ?? "" } let shareCommunityView = ShareCommunityView.shareCommunityView( title: "向好友传递美好生活,送TA 500彩虹豆", detailTitle: "越多好友看到,收获彩虹豆越多", h5Str: (self.communityPostDetailModel?.h5url ?? "" + "\(UserModel.shared().getModel()?.inviteCode ?? "")"), thumbnailImg: UIImage.imageUrl(self.communityPostDetailModel?.img), sharedTitle: String(title ?? ""), sharedDetailTitle: kCommunityPostDetailTitleShare, shareCommunityViewType: ShareCommunityViewType.postDetail, completion: { VirusViewModel.shared.forwarVirueRecordAddApi(postId: self.communityPostDetailModel?.id, postAuthorUid: "\(self.communityPostDetailModel?.uid ?? 0)", title: self.communityPostDetailModel?.title, content: self.communityPostDetailModel?.content, postType: self.communityPostDetailModel?.type, postCover: self.communityPostDetailModel?.img) }) shareCommunityView.saveCompletion = { [weak self] in let vc = CommunityShareContentViewController() vc.imgUrl = self?.communityPostDetailModel?.img let communityPostDetailTopicModel = self?.communityPostDetailModel?.topic?[0] vc.topicStr = communityPostDetailTopicModel?.name ?? "" if self?.communityPostDetailModel?.title == "" || self?.communityPostDetailModel?.title == nil { vc.titleStr = String(self?.communityPostDetailModel?.content?.prefix(20) ?? "") }else { vc.titleStr = String(self?.communityPostDetailModel?.title?.prefix(20) ?? "") } vc.avatarStr = self?.communityPostDetailModel?.avatar vc.nameStr = self?.communityPostDetailModel?.username vc.H5UrlStr = (self?.communityPostDetailModel?.h5url ?? "" + "\(UserModel.shared().getModel()?.inviteCode ?? "")") vc.bean = self?.communityPostDetailModel?.willCollectBean vc.postId = self?.communityPostDetailModel?.id vc.uid = self?.communityPostDetailModel?.uid vc.type = self?.communityPostDetailModel?.type vc.contentStr = self?.communityPostDetailModel?.content self?.navigationController?.pushViewController(vc, animated: true) } } } extension CommunityRecommendController { /// 帖子内容 func communityPostDetailApi() { SwiftMoyaNetWorkServiceCommunity.shared().communityPostDetailApi(id: id) { [weak self] (communityPostDetailModel) -> (Void) in self?.communityPostDetailModel = communityPostDetailModel as? CommunityPostDetailModel self?.communityPostsApi(page:1) self?.avatarButton.kf.setImage(with: kURLImage(name: self?.communityPostDetailModel?.avatar ?? ""), for: UIControl.State.normal, placeholder: kImage(name: "default_avatar")) self?.nameButton.setTitle(self?.communityPostDetailModel?.username, for: UIControl.State.normal) if self?.communityPostDetailModel?.uid == UserModel.shared().getModel()?.uid { self?.followButton.isHidden = true }else { self?.followButton.isHidden = false } CommunityFollowUserViewModel.shared.setFollowType(followButton: (self?.followButton)!, followType: FollowType(rawValue: self?.communityPostDetailModel?.isFollow ?? 0) ?? .futureFollow) self?.commentView.communityPostDetailModel = self?.communityPostDetailModel if PostType(rawValue: self?.communityPostDetailModel?.type ?? "html") == .html { self?.avatarButton.isHidden = true self?.nameButton.isHidden = true self?.followButton.isHidden = true }else { if self?.communityPostDetailModel?.uid != UserModel.shared().getModel()?.uid { self?.followButton.isHidden = false }else { self?.followButton.isHidden = true } if !(self?.communityPostDetailModel?.imgs?.isEmpty ?? true) { let height = getImageHeight(imgStr: (self?.communityPostDetailModel?.imgs?[0])!) let width = getImageWidth(imgStr: (self?.communityPostDetailModel?.imgs?[0])!) self?.communityPostDetailTableViewHeaderView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth*height/width) self?.communityPostDetailTableViewHeaderView.tableView = self?.tableView self?.tableView.tableHeaderView = self?.communityPostDetailTableViewHeaderView }else { if self?.communityPostDetailModel?.img != nil || self?.communityPostDetailModel?.img != "" { let height = getImageHeight(imgStr: (self?.communityPostDetailModel?.img)!) let width = getImageWidth(imgStr: (self?.communityPostDetailModel?.img)!) self?.communityPostDetailTableViewHeaderView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth*height/width) self?.communityPostDetailTableViewHeaderView.tableView = self?.tableView self?.tableView.tableHeaderView = self?.communityPostDetailTableViewHeaderView } } self?.communityPostDetailTableViewHeaderView.communityPostDetailModel = self?.communityPostDetailModel } self?.tableView.reloadData() self?.readVirueRecordAddApi() } } /// 阅读virue func readVirueRecordAddApi() { var postDesc : String? if self.communityPostDetailModel?.title == nil || self.communityPostDetailModel?.title == "" { postDesc = "\(self.communityPostDetailModel?.content?.prefix(20) ?? "")" }else { postDesc = self.communityPostDetailModel?.title } VirusViewModel.shared.readVirueRecordAddApi(postId: self.communityPostDetailModel?.id, postAuthorUid: "\(self.communityPostDetailModel?.uid ?? 0)", postDesc: postDesc, postType: self.communityPostDetailModel?.type, postCover: self.communityPostDetailModel?.img, actionId: "\(self.communityPostDetailModel?.id ?? 0)") } /// 评论列表 /// /// - Parameters: /// - postId: 内容id /// - page: 分页 func communityPostCommentApi(page:Int) { SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentsApi(postId: id, page: page) { [weak self] (communityPostCommentsModel) -> (Void) in self?.communityPostCommentsModel = communityPostCommentsModel as? CommunityPostCommentsModel self?.count = self?.communityPostCommentsModel?.pagination?.total ?? 0 if self?.communityPostCommentsModel?.pagination?.currentPage == 1{ self?.communityPostCommentModels.removeAll() } self?.communityPostCommentModels = (self?.communityPostCommentModels)! + (self?.communityPostCommentsModel?.data!)! self?.tableView.reloadData() } } /// 相关推荐 /// /// - Parameter page: 分页 func communityPostsApi(page:Int) { SwiftMoyaNetWorkServiceCommunity.shared().communityPostsApi(topicIds:"[\(self.communityPostDetailModel?.topicIds ?? "")]", page: page) { [weak self] (communityPostsModel) -> (Void) in let communityPostsModel = communityPostsModel as? CommunityPostsModel if communityPostsModel?.pagination?.currentPage ?? 1 <= communityPostsModel?.pagination?.totalPages ?? 1 { if communityPostsModel?.pagination?.currentPage == 1{ self?.communityPostDataModels.removeAll() } self?.communityPostDataModels = (self?.communityPostDataModels)! + (communityPostsModel?.data!)! self?.heightList() self?.tableView.reloadData() if self?.communityPostDataModels.count ?? 0 >= communityPostsModel?.pagination?.total ?? 0 { self?.tableView.endFooterNoMoreData() } }else { self?.tableView.endFooterNoMoreData() } } } /// 获取高度 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) } } } /// 评论 func communityPostCommentApi(text:String,complete: @escaping () -> ()) { let communityCustomCommnetModel = CommunityCustomCommnetModel() communityCustomCommnetModel.postId = communityPostDetailModel?.id ?? 0 communityCustomCommnetModel.content = text if communityPostCommentModel != nil { communityCustomCommnetModel.parentId = communityPostCommentModel?.id communityCustomCommnetModel.replyUid = communityPostCommentModel?.uid communityCustomCommnetModel.replyUsername = communityPostCommentModel?.username } SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) { [weak self] (communityPostCommentIdModel) -> (Void) in let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel if self?.communityPostCommentModel == nil { //评 let communityPostCommentModel = CommunityPostCommentModel() communityPostCommentModel.avatar = UserModel.shared().getModel()?.avatarurl communityPostCommentModel.content = text communityPostCommentModel.createdAt = "刚刚" communityPostCommentModel.id = communityPostCommentIdModel?.id communityPostCommentModel.username = UserModel.shared().getModel()?.username communityPostCommentModel.uid = UserModel.shared().getModel()?.uid self?.communityPostCommentModels.insert(communityPostCommentModel, at: 0) VirusViewModel.shared.comment(communityPostDetailModel: (self?.communityPostDetailModel)!, id: communityPostCommentIdModel?.id ?? 0,content: text) self?.count += 1 self?.communityPostDetailModel?.commentCount = self?.count self?.commentView.communityPostDetailModel = self?.communityPostDetailModel self?.tableView.reloadData() }else { //回评论 let communityPostReplyModel = CommunityPostReplyModel() communityPostReplyModel.avatar = UserModel.shared().getModel()?.avatarurl communityPostReplyModel.content = text communityPostReplyModel.createdAt = "刚刚" communityPostReplyModel.id = communityPostCommentIdModel?.id communityPostReplyModel.username = UserModel.shared().getModel()?.username communityPostReplyModel.uid = UserModel.shared().getModel()?.uid let count = self?.communityPostCommentModel?.replyCount ?? 0 + 1 self?.communityPostCommentModel?.replyCount = count if self?.communityPostCommentModel?.reply == nil { self?.communityPostCommentModel?.reply = Array() } self?.communityPostCommentModel?.reply?.insert(communityPostReplyModel, at: 0) VirusViewModel.shared.comment(communityPostDetailModel: (self?.communityPostDetailModel)!, id: communityPostCommentIdModel?.id ?? 0,content: text, communityPostCommentModel: self?.communityPostCommentModel) self?.tableView.reloadData() } complete() } } } // MARK: - tableView dataSource && delegate extension CommunityRecommendController: UITableViewDataSource, UITableViewDelegate { func numberOfSections(in tableView: UITableView) -> Int { return 3 } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { switch section { case 0: if communityPostDetailModel != nil { return 1 }else { return 0 } case 1: return communityPostCommentModels.isEmpty ? 1 : communityPostCommentModels.count case 2: return 1 default: return 0 } } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { switch indexPath.section { case 0: if PostType(rawValue: communityPostDetailModel?.type ?? "html") == .html { let cell = CommunityRecommendDetailHTMLTableViewCell.cellWith(tableView: tableView, indexPath: indexPath) cell.communityPostDetailModel = communityPostDetailModel cell.frame = tableView.bounds cell.layoutIfNeeded() cell.reloadData() cell.heightModel = heightModel1 cell.tableView = tableView return cell }else { let cell = RecommendDetailContentCell.cellWith(tableView: tableView, indexPath: indexPath) cell.communityPostDetailModel = communityPostDetailModel cell.frame = tableView.bounds cell.layoutIfNeeded() cell.reloadData() cell.heightModel = heightModel1 return cell } case 1: if communityPostCommentModels.isEmpty { let cell = RecommendNoneCommentCell.cellWith(tableView: tableView, indexPath: indexPath) cell.communityPostDetailModel = communityPostDetailModel cell.commentClosure = { [weak self] in self?.showKeyBoardCommentView(placeholder: "添加评论...") self?.hiddenKeyBoardCommentView() } cell.userClosure = { [weak self] in if self?.communityPostDetailModel?.uid != UserModel.shared().getModel()?.uid { let vc = OtherPersonalCenterViewController() vc.uid = self?.communityPostDetailModel?.uid ?? 0 self?.navigationController?.pushViewController(vc, animated: true) } } return cell }else { let cell = RecommendMajorCommentCell.cellWith(tableView: tableView, indexPath: indexPath) cell.communityPostDetailModel = communityPostDetailModel cell.communityPostCommentModel = communityPostCommentModels[indexPath.row] cell.frame = tableView.bounds cell.layoutIfNeeded() cell.reloadData() return cell } case 2: let cell = RecommendSimilarCell.cellWith(tableView: tableView, indexPath: indexPath) cell.heights = heights cell.communityPostDataModels = communityPostDataModels cell.frame = tableView.bounds cell.layoutIfNeeded() cell.reloadData() cell.heightModel = heightModel return cell default: return UITableViewCell() } } func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) { switch indexPath.section { case 0: if PostType(rawValue: communityPostDetailModel?.type ?? "html") == .html { }else { } case 1: if communityPostCommentModels.isEmpty { break }else { communityPostCommentModel = self.communityPostCommentModels[indexPath.row] self.indexPath = indexPath AlertSheetView.sheetCommentReplyView(userName: communityPostCommentModel?.username ?? "", content: communityPostCommentModel?.content ?? "") { [weak self] in self?.communityPostCommentModel = self?.communityPostCommentModels[indexPath.row] self?.showKeyBoardCommentView(placeholder: "回复:@\(self?.communityPostCommentModel?.username ?? "")") self?.hiddenKeyBoardCommentView() } break } case 2: break default: break } } func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { switch indexPath.section { case 0: return heightModel1.height ?? 0 case 1: if communityPostCommentModels.isEmpty { return 132 }else { return communityPostCommentModels[indexPath.row].height ?? 0 } case 2: return heightModel.height ?? 0 default: return 0 } } func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat { switch section { case 0: return 0.000001 case 1: if communityPostCommentModels.isEmpty { return 0.000001 }else { return 64 } case 2: return 52 default: return 0.000001 } } func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? { switch section { case 0: return UIView() case 1: if communityPostCommentModels.isEmpty { return UIView() }else { let headerView = RecommendCommentHeader(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 64)) headerView.count = count return headerView } case 2: return RecommendSimilarHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 52)) default: return UIView() } } func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat { switch section { case 0: return 10 case 1: if communityPostCommentModels.isEmpty { return 0.000001 }else { if communityPostCommentsModel?.pagination?.currentPage ?? 0 >= communityPostCommentsModel?.pagination?.totalPages ?? 0 { return 0.000001 }else { return 51 } } case 2: return 0.000001 default: return 0.000001 } } func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? { switch section { case 0: return UIView() case 1: if communityPostCommentModels.isEmpty { return UIView() }else { if communityPostCommentsModel?.pagination?.currentPage ?? 0 >= communityPostCommentsModel?.pagination?.totalPages ?? 0 { return UIView() }else { let footerView = RecommendCommentFooter(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 51)) footerView.unfoldClosure = { [weak self] in self?.communityPostCommentApi(page: (self?.communityPostCommentsModel?.pagination?.currentPage ?? 0) + 1) } return footerView } } case 2: return UIView() default: return UIView() } } } // MARK: - scrollView extension CommunityRecommendController { func scrollViewWillBeginDragging(_ scrollView: UIScrollView) { lastContentOffset = scrollView.contentOffset.y } func scrollViewWillBeginDecelerating(_ scrollView: UIScrollView) { if lastContentOffset < scrollView.contentOffset.y { sharedButton.isHidden = true }else{ sharedButton.isHidden = false } } func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { sharedButton.isHidden = false } }