123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636 |
- //
- // CommunityFeaturedTopicsViewController.swift
- // RainbowPlanet
- //
- // Created by 南鑫林 on 2019/6/16.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- //
- import UIKit
- import Kingfisher
- import SwiftyMediator
- class CommunityFeaturedTopicsViewController: BaseViewController {
-
- override func didReceiveMemoryWarning() {
- super.didReceiveMemoryWarning()
- KingfisherManager.shared.cache.clearDiskCache()
- KingfisherManager.shared.cache.clearMemoryCache()
- }
-
- deinit {
- NXLLog("deinit")
- if observe != nil {
- NotificationCenter.default.removeObserver(observe!)
- }
- }
- weak var observe : NSObjectProtocol?
-
- var id : Int = 0
- var communityRecommendDataModels = Array<CommunityRecommendDataModel>()
- var communityTopicDetailModel : CommunityTopicDetailModel?
-
- /// 评论需要的模型
- var communityRecommendDataModel : CommunityRecommendDataModel?
-
- override func viewDidLoad() {
- super.viewDidLoad()
- setupViews()
- setupData()
- setupLayouts()
- }
-
- override func viewWillAppear(_ animated: Bool) {
- super.viewWillAppear(animated)
- communityTopicDetailApi()
- }
-
- override func setupViews() {
- view.backgroundColor = UIColor.white
- view.addSubview(bgImageView)
- view.addSubview(bgView)
- view.addSubview(tableView)
- view.insertSubview(navigationBar, aboveSubview: tableView)
- setnavigationBar()
- }
-
-
- /// 设置navigationBar
- func setnavigationBar() {
- navigationBar.addSubview(navigationBgView)
- navigationBar.addSubview(topicLable)
- navigationBar.addSubview(focusButton)
- navigationBar.insertSubview(navigationBgView, aboveSubview: navigationBar.backgroundImageView)
- navigationBar.backgroundImageView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenWidth)
- navigationBar.clipsToBounds = true
- navigationBar.wr_setLeftButton(image: kImage(name: "navbar_back_white")!)
- navigationBar.wr_setRightButton(title: "我的话题", titleColor: .white)
- // 设置初始导航栏透明度
- navigationBar.wr_setBackgroundAlpha(alpha: 0)
- // 设置状态栏style
- statusBarStyle = .lightContent
- }
-
- override func setupLayouts() {
- bgImageView.snp_makeConstraints { (make) in
- make.top.left.right.equalToSuperview()
- make.height.equalTo(kScreenWidth)
- }
- bgView.snp.makeConstraints { (make) in
- make.top.left.right.equalToSuperview()
- make.height.equalTo(kScreenWidth)
- }
- tableView.snp.makeConstraints { (make) in
- make.top.left.right.bottom.equalToSuperview()
- }
- navigationBgView.snp_makeConstraints { (make) in
- make.edges.equalTo(navigationBar)
- }
- topicLable.snp_makeConstraints { (make) in
- make.centerY.equalTo(navigationBar.leftButton)
- make.left.equalTo(navigationBar.leftButton.snp_right)
- }
- focusButton.snp_makeConstraints { (make) in
- make.right.equalTo(-14)
- make.centerY.equalTo(navigationBar.leftButton)
- make.width.equalTo(60)
- make.height.equalTo(28)
- }
- }
-
- private lazy var tableView: UITableView = {
- let tableView = UITableView(frame: CGRect.zero, style: UITableView.Style.grouped)
- tableView.separatorStyle = .none
- tableView.backgroundColor = UIColor.clear
- tableView.dataSource = self
- tableView.delegate = self
- if #available(iOS 11.0, *) {
- tableView.contentInsetAdjustmentBehavior = .never
- }
- return tableView
- }()
-
- private lazy var bgImageView: UIImageView = {
- let bgImageView = UIImageView()
- bgImageView.contentMode = .scaleAspectFill
- bgImageView.clipsToBounds = true
- return bgImageView
- }()
-
- private lazy var bgView: UIView = {
- let bgView = UIView()
- bgView.backgroundColor = UIColor(hexString: "000000", alpha: 0.4)
- return bgView
- }()
-
- private lazy var communityFeaturedTopicsHeaderView: CommunityFeaturedTopicsHeaderView = {
- let communityFeaturedTopicsHeaderView = CommunityFeaturedTopicsHeaderView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 180 + kSafeStatusBarHeight))
- return communityFeaturedTopicsHeaderView
- }()
-
- private lazy var topicLable: UILabel = {
- let topicLable = UILabel()
- topicLable.textColor = kffffffColor
- topicLable.font = kRegularFont14
- topicLable.text = "运动健身"
- topicLable.alpha = 0
- return topicLable
- }()
-
- private lazy var focusButton: UIButton = {
- let focusButton = UIButton(type: UIButton.ButtonType.custom)
- focusButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
- focusButton.setTitleColor(kffffffColor, for: UIControl.State.selected)
- focusButton.setTitle("关注", for: UIControl.State.normal)
- focusButton.setTitle("已关注", for: UIControl.State.selected)
- focusButton.titleLabel?.font = kRegularFont13
- focusButton.setBackgroundImage(UIImage.imageWithColor(color: kThemeColor), for: UIControl.State.normal)
- focusButton.setBackgroundImage(UIImage.imageWithColor(color: UIColor.clear), for: UIControl.State.selected)
- focusButton.alpha = 0
- focusButton.layer.borderWidth = 0.5
- focusButton.layer.borderColor = kThemeColor.cgColor
- focusButton.cornerRadius = 14
- focusButton.masksToBounds = true
- focusButton.rx.tap.subscribe(onNext: { [weak self] (data) in
- if self?.communityTopicDetailModel?.isFollow == 1 {
- CommunityFollowTopicViewModel.shared.communityMemberFollowTopicCancelFollowApi(topicId: (self?.id)!, communityTopicDetailModel: (self?.communityTopicDetailModel!)!, communityFeaturedTopicsHeaderView: (self?.communityFeaturedTopicsHeaderView)!, button: (self?.focusButton)!, communityFollowTopicType: .view)
- }else {
- CommunityFollowTopicViewModel.shared.communityMemberFollowTopicFollowApi(topicId: (self?.id)!, communityTopicDetailModel: (self?.communityTopicDetailModel!)!, communityFeaturedTopicsHeaderView: (self?.communityFeaturedTopicsHeaderView)!, button: (self?.focusButton)!, communityFollowTopicType: .view)
- }
- }).disposed(by: disposeBag)
-
- return focusButton
- }()
-
- private lazy var navigationBgView: UIView = {
- let navigationBgView = UIView()
- navigationBgView.backgroundColor = UIColor(hexString: "000000", alpha: 0.4)
- navigationBgView.alpha = 0
- return navigationBgView
- }()
-
- override func setupData() {
- //下拉刷新
- tableView.addFullScreenHeader(withBeginRefresh: true, animation: true) {
- [weak self] (page) in
- self?.communityTopicDetailApi()
- self?.communityPostTopicApi(page: page)
- }
- tableView.addAutoNormalFooter(withAutomaticallyRefresh: true, loadMoreBlock: {
- [weak self] (page) in
- self?.communityPostTopicApi(page: page)
- })
- communityFeaturedTopicsHeaderView.followClosureName = {
- [weak self] in
- if self?.communityTopicDetailModel?.isFollow == 1 {
- CommunityFollowTopicViewModel.shared.communityMemberFollowTopicCancelFollowApi(topicId: (self?.id)!, communityTopicDetailModel: (self?.communityTopicDetailModel!)!, communityFeaturedTopicsHeaderView: (self?.communityFeaturedTopicsHeaderView)!, button: (self?.focusButton)!, communityFollowTopicType: .view)
- }else {
- CommunityFollowTopicViewModel.shared.communityMemberFollowTopicFollowApi(topicId: (self?.id)!, communityTopicDetailModel: (self?.communityTopicDetailModel!)!, communityFeaturedTopicsHeaderView: (self?.communityFeaturedTopicsHeaderView)!, button: (self?.focusButton)!, communityFollowTopicType: .view)
- }
- }
- navigationBar.onClickRightButton = {
- [weak self] in
- let vc = CommunityMyFollowTopicController()
- self?.navigationController?.pushViewController(vc, animated: true)
- }
-
- 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?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.uid == followStatusModel?.uid {
- communityRecommendDataModel.isFollow = followStatusModel?.isFollowStatus
- }
- }
- }
- 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?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.id == followStatusModel?.postId {
- communityRecommendDataModel.isDislike = followStatusModel?.isFollowStatus
- }
- }
- }
- 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?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.id == followStatusModel?.postId {
- communityRecommendDataModel.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?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.id == followStatusModel?.postId {
- communityRecommendDataModel.isCollect = followStatusModel?.isFollowStatus
- }
- }
- }
- self?.tableView.reloadData()
- }
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("isCommnetLikeApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
- let followStatusModel = notification.object as? FollowStatusModel
- if !(self?.communityRecommendDataModels.isEmpty ?? true) {
- for communityRecommendDataModel in (self?.communityRecommendDataModels)! {
- if communityRecommendDataModel.id == followStatusModel?.postId {
- if !(communityRecommendDataModel.comment?.isEmpty ?? true ){
- for communityRecommendCommentModel in communityRecommendDataModel.comment! {
- if communityRecommendCommentModel.id == followStatusModel?.commnetId {
- communityRecommendCommentModel.isLike = followStatusModel?.isFollowStatus
- communityRecommendCommentModel.likeCount = followStatusModel?.commentLikeCount
- }
- }
- }
- }
- }
- }
- self?.tableView.reloadData()
- }
-
- observe = NotificationCenter.default.addObserver(forName: NSNotification.Name("communityDeletePostApi"), object: nil, queue: OperationQueue.main) { [weak self] (notification) in
- let postId = notification.object as? Int
- if !(self?.communityRecommendDataModels.isEmpty ?? true) {
- for (index,communityRecommendDataModel) in (self?.communityRecommendDataModels)!.enumerated() {
- if communityRecommendDataModel.id == postId {
- self?.communityRecommendDataModels.remove(at: index)
- }
- }
- self?.tableView.reloadData()
- }
- }
- }
-
-
- /// 显示键盘
- func showKeyBoardCommentView() {
- KeyBoardInputView.show(inputViewResultClosure: {
- [weak self] (text) in
- self?.communityPostCommentApi(text: text, complete: {
- [weak self] in
- self?.communityRecommendDataModel = nil
- })
- }) {
- [weak self] in
- self?.communityRecommendDataModel = nil
- }
- }
-
- }
- extension CommunityFeaturedTopicsViewController {
- func scrollViewDidScroll(_ scrollView: UIScrollView)
- {
- let offsetY = scrollView.contentOffset.y
- if (offsetY > kSafeStatusBarHeight)
- {
- let alpha = (offsetY - kSafeStatusBarHeight) / CGFloat(kNavBarTotalHeight)
- navigationBar.wr_setBackgroundAlpha(alpha: alpha)
- focusButton.alpha = alpha
- topicLable.alpha = alpha
- navigationBgView.alpha = alpha
- navigationBar.rightButton.alpha = 1 - alpha
- }
- else
- {
- navigationBar.wr_setBackgroundAlpha(alpha: 0)
- focusButton.alpha = 0
- topicLable.alpha = 0
- navigationBgView.alpha = 0
- navigationBar.rightButton.alpha = 1
- }
- }
- }
- extension CommunityFeaturedTopicsViewController {
-
- /// 话题详情页面
- func communityTopicDetailApi() {
- SwiftMoyaNetWorkServiceCommunity.shared().communityTopicDetailApi(id: id) {
- [weak self] (communityTopicDetailModel) -> (Void) in
- self?.communityTopicDetailModel = communityTopicDetailModel as? CommunityTopicDetailModel
- self?.topicLable.text = self?.communityTopicDetailModel?.name
- CommunityFollowTopicViewModel.shared.followTopicButton(communityTopicDetailModel: self?.communityTopicDetailModel, button: self?.focusButton)
- self?.bgImageView.kf.setImage(with: kURLImage(name: self?.communityTopicDetailModel?.img ?? ""), placeholder: kImage(name: "default_pic"))
- self?.navigationBar.barBackgroundImage = self?.bgImageView.image
- self?.communityFeaturedTopicsHeaderView.communityTopicDetailModel = self?.communityTopicDetailModel
- self?.tableView.tableHeaderView = self?.communityFeaturedTopicsHeaderView
- }
- }
-
- /// 话题帖子
- func communityPostTopicApi(page:Int) {
- SwiftMoyaNetWorkServiceCommunity.shared().communityPostTopicApi(id: id, page: page, completion: {
- [weak self] (communityRecommendFeedModel) -> (Void) in
- let communityRecommendFeedModel = communityRecommendFeedModel as? CommunityRecommendFeedModel
- if communityRecommendFeedModel?.pagination?.currentPage == 1{
- self?.communityRecommendDataModels.removeAll()
- self?.tableView.resetNoMoreData()
- }
- self?.communityRecommendDataModels = (self?.communityRecommendDataModels)! + (communityRecommendFeedModel?.data!)!
- self?.tableView.reloadData()
- MJRefreshManager.mjRefreshManagerPaginationNoHiddenFooter(tableView: self?.tableView, pagination: communityRecommendFeedModel?.pagination)
- }) {
- [weak self] loadingStatus in
- MJRefreshManager.mjRefreshManagerLoadingStatus(tableView: self?.tableView,loadingStatus: loadingStatus)
- }
- }
-
- /// 评论
- func communityPostCommentApi(text:String,complete: @escaping () -> ()) {
- let communityCustomCommnetModel = CommunityCustomCommnetModel()
- communityCustomCommnetModel.postId = communityRecommendDataModel?.id ?? 0
- communityCustomCommnetModel.content = text
- SwiftMoyaNetWorkServiceCommunity.shared().communityPostCommentApi(communityCustomCommnetModel: communityCustomCommnetModel) {
- [weak self] (communityPostCommentIdModel) -> (Void) in
-
- let communityPostCommentIdModel = communityPostCommentIdModel as? CommunityPostCommentIdModel
-
- let communityRecommendCommentModel = CommunityRecommendCommentModel()
- communityRecommendCommentModel.content = text
- communityRecommendCommentModel.id = communityPostCommentIdModel?.id
- communityRecommendCommentModel.username = UserModel.shared().getModel()?.username
- communityRecommendCommentModel.uid = UserModel.shared().getModel()?.uid
-
- if self?.communityRecommendDataModel?.comment?.isEmpty ?? true {
- self?.communityRecommendDataModel?.comment = Array<CommunityRecommendCommentModel>()
- }
-
- self?.communityRecommendDataModel?.comment?.insert(communityRecommendCommentModel, at: 0)
-
- VirusViewModel.shared.comment(communityRecommendDataModel: self?.communityRecommendDataModel, id: communityPostCommentIdModel?.id ?? 0,content: text)
- let count = self?.communityRecommendDataModel?.commentCount ?? 0 + 1
- self?.communityRecommendDataModel?.commentCount = count
- self?.tableView.reloadData()
- complete()
- }
- }
-
- /// 删除帖子
- func communityDeleteApi(postId:Int,section:Int) {
- SwiftMoyaNetWorkServiceCommunity.shared().communityDeleteApi(postId: postId) { [weak self] (data) -> (Void) in
- self?.communityRecommendDataModels.remove(at: section)
- self?.tableView.reloadData()
- }
- }
-
- }
- extension CommunityFeaturedTopicsViewController : UITableViewDelegate,UITableViewDataSource {
-
- func numberOfSections(in tableView: UITableView) -> Int {
- return communityRecommendDataModels.isEmpty ? 0 : communityRecommendDataModels.count
- }
-
- func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
- return 6
- }
-
- func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
- let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
- switch indexPath.row {
- //贴子用户
- case 0:
- let cell = CardContentUserTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- let shapeLayer = CAShapeLayer()
- cell.layer.mask = nil
- if indexPath.section == 0 {
- let bezierPath = UIBezierPath(roundedRect: cell.bounds,byRoundingCorners: [.topLeft,.topRight],cornerRadii: CGSize(width: 8,height: 8))
- shapeLayer.path = bezierPath.cgPath
- cell.layer.mask = shapeLayer
- }else {
- let bezierPath = UIBezierPath(roundedRect: cell.bounds,byRoundingCorners: [.allCorners],cornerRadii: CGSize(width: 0,height: 0))
- shapeLayer.path = bezierPath.cgPath
- cell.layer.mask = shapeLayer
- }
- cell.followClosure = {
- [weak self] in
- CommunityFollowUserViewModel.shared.follow(communityRecommendDataModel: communityRecommendDataModel, communityRecommendDataModels: (self?.communityRecommendDataModels)!, tableView: (self?.tableView)!)
- }
- cell.likeClosure = {[weak self] y in
- if UserModel.shared().isEqualUid(uid: communityRecommendDataModel.uid ?? 0) {
- CardContentUserDeleteView.sheetDeleteView(y: y, sureClosure: { [weak self] (cardContentUserDeleteView) in
- self?.communityDeleteApi(postId: communityRecommendDataModel.id ?? 0, section: indexPath.section)
- })
- }else {
- VirusViewModel.shared.like(communityRecommendDataModel: communityRecommendDataModel, y: y, tableView: (self?.tableView)!)
-
- }
- }
- return cell
- //图片视频
- case 1:
- let cell = CardContentPicVideoTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.type = .recommend
- cell.communityRecommendDataModel = communityRecommendDataModel
- return cell
- //内容标题
- case 2:
- let cell = CardContentTitleTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- return cell
- //点赞,收藏,分享
- case 3:
- let cell = CardContentActionTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- cell.praiseClosureName = {
- [weak self] (button:UIButton) in
- VirusViewModel.shared.praise(communityRecommendDataModel: communityRecommendDataModel, tableView: (self?.tableView)!)
- }
- cell.collectClosureName = {
- [weak self] (button:UIButton) in
- VirusViewModel.shared.collection(communityRecommendDataModel: communityRecommendDataModel, tableView: (self?.tableView)!)
- }
- return cell
- //评论列表
- case 4:
- let cell = CardContentCommentListTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.communityRecommendDataModel = communityRecommendDataModel
- return cell
- //评论
- case 5:
- let cell = CardContentCommnetTableViewCell.cellWith(tableView: tableView, indexPath: indexPath)
- cell.addCommnetClosureName = {
- [weak self] in
- self?.communityRecommendDataModel = self?.communityRecommendDataModels[indexPath.section]
- self?.showKeyBoardCommentView()
- }
- cell.isAvatar = true
- return cell
- default:
- return UITableViewCell()
- }
-
- }
-
- func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
- let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
- switch indexPath.row {
- //贴子用户
- case 0:
- break
- //图片视频/内容标题/评论列表
- case 1,2:
- if PostType(rawValue: communityRecommendDataModel.type ?? "video") == .video {
- Mediator.push(CommunityRouterModuleType.pushPostDetailVoide(postId: "\(communityRecommendDataModel.id ?? 0)", departType: .others, topicId: 0))
- }else {
- Mediator.push(CommunityRouterModuleType.pushPostDetailContent(postId: "\(communityRecommendDataModel.id ?? 0)"))
- }
- break
- //点赞,收藏,分享
- case 3:
- break
- //评论
- case 5:
- break
- default:
- break
- }
- }
-
- func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
-
- let communityRecommendDataModel = communityRecommendDataModels[indexPath.section]
- switch indexPath.row {
- //贴子用户
- case 0:
- if communityRecommendDataModel.uid != nil {
- return 80
- }
- return 0
- //图片视频
- case 1:
-
- let cardContentPicVideoModel = CardContentPicVideoModel()
- cardContentPicVideoModel.postType = PostType(rawValue: communityRecommendDataModel.type ?? "html")
-
- let imgStr = communityRecommendDataModel.img
- if communityRecommendDataModel.imgs?.count ?? 0 == 0 {
- if communityRecommendDataModel.img != "" && communityRecommendDataModel.img != nil {
- cardContentPicVideoModel.number = 1
- cardContentPicVideoModel.width = getImageWidth(imgStr: (imgStr)!)
- cardContentPicVideoModel.height = getImageHeight(imgStr: (imgStr)!)
- return cardContentPicVideoModel.collectionViewHeight() + 15
- }else {
- return 0
- }
- }else {
- if communityRecommendDataModel.imgs?.count ?? 0 == 1 {
- if communityRecommendDataModel.img != "" || communityRecommendDataModel.img != nil {
- cardContentPicVideoModel.number = 1
- cardContentPicVideoModel.width = getImageWidth(imgStr: (imgStr)!)
- cardContentPicVideoModel.height = getImageHeight(imgStr: (imgStr)!)
- return cardContentPicVideoModel.collectionViewHeight() + 15
- }else {
- return 0
- }
- }else {
- cardContentPicVideoModel.number = communityRecommendDataModel.imgs?.count ?? 0
- return cardContentPicVideoModel.collectionViewHeight() + 15
- }
- }
- //内容标题
- case 2:
- var str = communityRecommendDataModel.content ?? ""
- str = str.replacingOccurrences(of: "\n", with: "").replacingOccurrences(of: "\r", with: "")
- if (communityRecommendDataModel.title == "" || communityRecommendDataModel.title == nil) {
- if str.count >= 45 {
- str = str.prefix(45) + "...更多"
- let contentHeight = "\(str)".heightForComment(font: kRegularFont14!, width: kScreenWidth-28)
- return contentHeight
- }else {
- let contentHeight = "\(str)".heightForComment(font: kRegularFont14!, width: kScreenWidth-28)
- return contentHeight
- }
- }else {
- if PostType(rawValue: communityRecommendDataModel.type ?? "html") == .html {
- return 22
- }else {
- if communityRecommendDataModel.content?.count ?? 0 >= 45 {
- str = str.prefix(45) + "...更多"
- let contentHeight = "\(str)".heightForComment(font: kRegularFont14!, width: kScreenWidth-28)
- return (22 + 6 + contentHeight)
- }else {
- let contentHeight = "\(str)".heightForComment(font: kRegularFont14!, width: kScreenWidth-28)
- return 22 + 6 + contentHeight
- }
- }
- }
- //点赞,收藏,分享
- case 3:
- return 54
- //评论列表
- case 4:
- if !(communityRecommendDataModel.comment?.isEmpty ?? true) {
-
- var height : CGFloat?
- for communityRecommendCommentModel in communityRecommendDataModel.comment!.prefix(2) {
-
- let nameStr = "\(communityRecommendCommentModel.username ?? ""):"
- let contentStr = "\(communityRecommendCommentModel.content ?? "")"
- let likeCountStr = "\(communityRecommendCommentModel.likeCount ?? 0)"
- let likeWidth = likeCountStr.widthForComment(font: kRegularFont14!, height: 25.5)
-
- let str = nameStr + contentStr
- let strHeight = (str.heightForComment(font: kRegularFont14!, width: kScreenWidth-28-10-16-5-likeWidth) + 5)
- height = (height ?? 0) + strHeight
- }
-
- if (communityRecommendDataModel.commentCount ?? 0) <= 2 {
- return (height ?? 0)
- }else {
- return 23 + (height ?? 0)
- }
- }
- return 0
- //评论
- case 5:
- return 50
- default:
- return 0
- }
- }
-
- func tableView(_ tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
- return 0.000001
-
- }
-
- func tableView(_ tableView: UITableView, heightForFooterInSection section: Int) -> CGFloat {
- return 10
- }
-
- func tableView(_ tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {
-
- return nil
- }
-
- func tableView(_ tableView: UITableView, viewForFooterInSection section: Int) -> UIView? {
- let view = UIView(frame: CGRect(x: 0, y: 0, width: kScreenWidth, height: 10))
- view.backgroundColor = kf7f8faColor
- return view
- }
- }
|