CommunityVideoCoverCollectionCell.swift 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. //
  2. // CommunityVideoCoverCollectionCell.swift
  3. // RainbowPlanet
  4. //
  5. // Created by Christopher on 2019/7/3.
  6. // Copyright © 2019 RainbowPlanet. All rights reserved.
  7. // 视频播放列表のCell
  8. import UIKit
  9. import RxSwift
  10. enum videoBtnClickType {
  11. case typeComment
  12. case typeLike
  13. case typeCollect
  14. case typePerson
  15. }
  16. class CommunityVideoCoverCollectionCell: UICollectionViewCell {
  17. let disposeBag = DisposeBag()
  18. typealias BackClosure = () -> Void
  19. var backClosure : BackClosure?
  20. typealias ShareClosure = (_ videoItemMdl: CommunityVideoItemModel) -> Void
  21. var shareClosure : ShareClosure?
  22. typealias ButtonClickClosure = (_ clickType: videoBtnClickType, _ uid: Int, _ postId: Int) -> Void
  23. var buttonClickClosure : ButtonClickClosure?
  24. typealias FollowClosure = (_ videoItemMdl: CommunityVideoItemModel, _ button: UIButton) -> Void
  25. var followClosure : FollowClosure?
  26. class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> CommunityVideoCoverCollectionCell {
  27. let ID = "CommunityVideoCoverCollectionCell"
  28. collectionView.register(CommunityVideoCoverCollectionCell.self, forCellWithReuseIdentifier: ID)
  29. let cell : CommunityVideoCoverCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: ID, for: indexPath) as! CommunityVideoCoverCollectionCell
  30. cell.indexPath = indexPath
  31. return cell
  32. }
  33. //MARK: indexPath
  34. var indexPath: IndexPath?{
  35. didSet {
  36. }
  37. }
  38. //MARK: - 初始化
  39. override init(frame: CGRect) {
  40. super.init(frame: frame)
  41. backgroundColor = UIColor.black
  42. setupViews()
  43. setupLayouts()
  44. }
  45. // Neccessary - 清除待复用Cell原先的player
  46. override func prepareForReuse() {
  47. super.prepareForReuse()
  48. videoPlayView.cancelLoading()
  49. }
  50. required init?(coder aDecoder: NSCoder) {
  51. fatalError("init(coder:) has not been implemented")
  52. }
  53. //MARK: - 设置View
  54. private func setupViews() {
  55. // 视频播放
  56. addSubview(videoPlayView)
  57. videoPlayView.addTapGesture(1, target: self, action: #selector(videoTapAction))
  58. addSubview(bottomSepView)
  59. addSubview(bgView)
  60. // 顶部渐变
  61. addSubview(topGradientView)
  62. // 顶部
  63. topGradientView.addSubview(navBackView)
  64. navBackView.addSubview(navBackBtn)
  65. navBackView.addSubview(shareBtnRight)
  66. navBackView.addSubview(shareBtnLeft)
  67. // 底部渐变
  68. addSubview(bottomGradientView)
  69. bottomGradientView.addTapGesture(1, target: self, action: #selector(videoTapAction))
  70. // 底部
  71. bottomGradientView.addSubview(bottomCommentView)
  72. bottomCommentView.addSubview(commentBtn)
  73. bottomCommentView.addSubview(collectBtn)
  74. bottomCommentView.addSubview(likeBtn)
  75. bottomCommentView.addSubview(commentView)
  76. commentView.addSubview(commentLabel)
  77. commentView.addSubview(textBtn)
  78. // 话题View
  79. bottomGradientView.addSubview(topicView)
  80. // 视频内容
  81. bottomGradientView.addSubview(contentScrollView)
  82. contentScrollView.addSubview(contentLabel)
  83. bottomGradientView.addSubview(unfoldButton)
  84. unfoldButton.isHidden = true
  85. // 视频标题
  86. bottomGradientView.addSubview(videoTitleLabel)
  87. bottomGradientView.addSubview(personBackView)
  88. personBackView.addSubview(avatarButton)
  89. personBackView.addSubview(personLabel)
  90. personBackView.addSubview(followButton)
  91. bottomGradientView.addSubview(rainbowBeanView)
  92. rainbowBeanView.addSubview(beanIconImageView)
  93. rainbowBeanView.addSubview(beanLabel)
  94. addSubview(playStatusImageView)
  95. }
  96. private func setupLayouts() {
  97. // 视频播放
  98. videoPlayView.snp.makeConstraints { (make) in
  99. make.edges.equalToSuperview()
  100. }
  101. // 顶部
  102. navBackView.snp.makeConstraints { (make) in
  103. make.top.equalTo(kSafeStatusBarHeight)
  104. make.left.right.equalToSuperview()
  105. make.height.equalTo(44)
  106. }
  107. navBackBtn.snp.makeConstraints { (make) in
  108. make.left.equalTo(5)
  109. make.centerY.equalToSuperview()
  110. make.size.equalTo(40)
  111. }
  112. shareBtnRight.snp.makeConstraints { (make) in
  113. make.right.equalTo(-6)
  114. make.centerY.equalToSuperview()
  115. make.size.equalTo(39)
  116. }
  117. shareBtnLeft.snp.makeConstraints { (make) in
  118. make.right.equalTo(-52)
  119. make.bottom.equalTo(-8)
  120. make.width.equalTo(123)
  121. make.height.equalTo(35)
  122. }
  123. // 底部
  124. bottomCommentView.snp.makeConstraints { (make) in
  125. make.bottom.equalTo(-kSafeTabBarHeight)
  126. make.left.right.equalToSuperview()
  127. make.height.equalTo(60)
  128. }
  129. bottomSepView.snp.makeConstraints { (make) in
  130. make.left.right.equalToSuperview()
  131. make.height.equalTo(0.5)
  132. make.bottom.equalToSuperview().offset(-(kSafeTabBarHeight + 60))
  133. }
  134. commentBtn.snp.makeConstraints { (make) in
  135. make.right.equalToSuperview().offset(-14)
  136. make.centerY.equalToSuperview()
  137. make.height.equalTo(24)
  138. }
  139. commentBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
  140. collectBtn.snp.makeConstraints { (make) in
  141. make.right.equalTo(commentBtn.snp_left).offset(-15)
  142. make.centerY.equalToSuperview()
  143. make.height.equalTo(37)
  144. }
  145. collectBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
  146. likeBtn.snp.makeConstraints { (make) in
  147. make.right.equalTo(collectBtn.snp_left).offset(-15)
  148. make.centerY.equalToSuperview()
  149. make.height.equalTo(37)
  150. }
  151. likeBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
  152. commentView.snp.makeConstraints { (make) in
  153. make.centerY.equalToSuperview()
  154. make.left.equalToSuperview().offset(14)
  155. make.right.equalTo(likeBtn.snp_left).offset(-10)
  156. make.height.equalTo(30)
  157. }
  158. commentLabel.snp.makeConstraints { (make) in
  159. make.left.equalTo(15)
  160. make.centerY.equalToSuperview()
  161. make.width.equalTo(70)
  162. make.height.equalTo(28)
  163. }
  164. textBtn.snp.makeConstraints { (make) in
  165. make.edges.equalToSuperview()
  166. }
  167. // 话题View
  168. topicView.snp.makeConstraints { (make) in
  169. make.bottom.equalTo(bottomCommentView.snp_top)
  170. make.left.right.equalToSuperview()
  171. make.height.equalTo(45)
  172. }
  173. // 视频内容
  174. contentScrollView.snp.makeConstraints { (make) in
  175. make.bottom.equalTo(topicView.snp_top)
  176. make.left.equalTo(14)
  177. make.right.equalTo(-14)
  178. make.height.equalTo(44)
  179. }
  180. contentLabel.snp.makeConstraints { (make) in
  181. make.top.left.equalToSuperview()
  182. make.width.equalTo(kScreenWidth-28)
  183. make.height.equalTo(44)
  184. }
  185. // 视频标题
  186. videoTitleLabel.snp.makeConstraints { (make) in
  187. make.left.equalTo(14)
  188. make.right.equalTo(-14)
  189. make.height.equalTo(23)
  190. make.bottom.equalTo(contentScrollView.snp_top).offset(-10)
  191. }
  192. // personView
  193. personBackView.snp.makeConstraints { (make) in
  194. make.left.equalTo(14)
  195. make.height.equalTo(30)
  196. make.bottom.equalTo(videoTitleLabel.snp_top).offset(-20)
  197. }
  198. avatarButton.snp.makeConstraints { (make) in
  199. make.left.top.equalToSuperview()
  200. make.size.equalTo(30)
  201. }
  202. personLabel.snp.makeConstraints { (make) in
  203. make.left.equalTo(avatarButton.snp_right).offset(10)
  204. make.centerY.equalToSuperview()
  205. make.height.equalTo(18)
  206. }
  207. followButton.snp.makeConstraints { (make) in
  208. make.left.equalTo(personLabel.snp_right).offset(10)
  209. make.centerY.equalToSuperview()
  210. make.width.equalTo(64)
  211. make.height.equalTo(20)
  212. make.right.equalToSuperview()
  213. }
  214. // 彩虹豆View
  215. rainbowBeanView.snp.makeConstraints { (make) in
  216. make.left.equalTo(14)
  217. make.height.equalTo(24)
  218. make.bottom.equalTo(personBackView.snp_top).offset(-10)
  219. }
  220. // rainbowBeanView.snp.makeConstraints { (make) in
  221. // make.top.equalTo(10)
  222. // make.left.equalTo(14)
  223. // make.height.equalTo(24)
  224. // make.bottom.equalTo(personBackView.snp_top).offset(-10)
  225. // }
  226. beanIconImageView.snp.makeConstraints { (make) in
  227. make.left.equalTo(6)
  228. make.centerY.equalToSuperview()
  229. make.size.equalTo(19)
  230. }
  231. beanLabel.snp.makeConstraints { (make) in
  232. make.left.equalTo(beanIconImageView.snp_right).offset(5)
  233. make.top.bottom.equalToSuperview()
  234. make.right.equalTo(-6)
  235. }
  236. //
  237. playStatusImageView.snp.makeConstraints { (make) in
  238. make.center.equalToSuperview()
  239. make.width.equalTo(50)
  240. make.height.equalTo(60)
  241. }
  242. }
  243. func addSeeMoreButton(_ label: YYLabel, textStr: String?) {
  244. label.attributedText = NSAttributedString(string: textStr ?? "", attributes: [
  245. NSAttributedString.Key.foregroundColor: kffffffColor,
  246. NSAttributedString.Key.font: kRegularFont14!
  247. ])
  248. let moreString = " 展开"
  249. let text = NSMutableAttributedString(string: "... \(moreString)")
  250. let expandRange = (text.string as NSString).range(of: moreString)
  251. text.addAttribute(.foregroundColor, value: kffffffColor, range: expandRange)
  252. text.addAttribute(.font, value: kMediumFont24!, range: expandRange)
  253. text.addAttribute(.foregroundColor, value: kffffffColor, range: NSRange(location: 0, length: expandRange.location))
  254. //添加点击事件
  255. let hi = YYTextHighlight()
  256. text.yy_setTextHighlight(hi, range: (text.string as NSString).range(of: moreString))
  257. hi.tapAction = {
  258. [weak self] (containerView, text, range, rect) in
  259. //点击展开
  260. self?.setTextFrame(true)
  261. }
  262. text.yy_font = kRegularFont14
  263. let seeMore = YYLabel()
  264. seeMore.attributedText = text
  265. seeMore.sizeToFit()
  266. let truncationToken = NSAttributedString.yy_attachmentString(withContent: seeMore, contentMode: UIView.ContentMode.center, attachmentSize: seeMore.frame.size, alignTo: text.yy_font!, alignment: YYTextVerticalAlignment.top)
  267. label.truncationToken = truncationToken
  268. }
  269. func setTextFrame(_ isExpand: Bool) {
  270. if isExpand {
  271. expandString()
  272. let size: CGSize = contentLabel.sizeThatFits(CGSize(width: kScreenWidth-28, height: CGFloat(MAXFLOAT)))
  273. print("------size == \(size)")
  274. contentScrollView.snp.remakeConstraints { (make) in
  275. make.bottom.equalTo(topicView.snp_top).offset(-40)
  276. make.left.equalTo(14)
  277. make.right.equalTo(-14)
  278. make.height.equalTo(size.height)
  279. }
  280. contentLabel.snp.remakeConstraints { (make) in
  281. make.top.left.equalToSuperview()
  282. make.width.equalTo(kScreenWidth-28)
  283. make.height.equalTo(size.height)
  284. }
  285. unfoldButton.snp.remakeConstraints { (make) in
  286. make.bottom.equalTo(topicView.snp_top).offset(-10)
  287. make.right.equalTo(-4)
  288. make.width.equalTo(48)
  289. make.height.equalTo(20)
  290. }
  291. unfoldButton.isHidden = false
  292. // 控件高度+间距+"收起"の高度
  293. let backHeight = (60+45+size.height+23+30+24) + (10+20+10+20) + 40
  294. UIView.animate(withDuration: 0.5) {
  295. [weak self] in
  296. self?.bottomGradientView.frame = CGRect(x: 0, y: kScreenHeight-backHeight-kSafeTabBarHeight, width: kScreenWidth, height: backHeight+kSafeTabBarHeight)
  297. }
  298. } else {
  299. // contentScrollView.frame = CGRect(x: 14, y: 0, width: UIScreen.main.bounds.size.width - 28, height: 30)
  300. // contentLabel.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width - 40, height: 30)
  301. }
  302. }
  303. func expandString() {
  304. let attri = contentLabel.attributedText as? NSMutableAttributedString
  305. contentLabel.attributedText = attri
  306. }
  307. lazy var bgView: UIView = {
  308. let bgView = UIView(frame: self.frame)
  309. bgView.backgroundColor = UIColor(hexString: "000000", alpha: 0.1)
  310. bgView.isUserInteractionEnabled = true
  311. return bgView
  312. }()
  313. // MARK: 视频播放View
  314. private lazy var videoPlayView: CommunityVideoPlayView = {
  315. let videoPlayView = CommunityVideoPlayView()
  316. videoPlayView.isUserInteractionEnabled = true
  317. return videoPlayView
  318. }()
  319. // MARK: 渐变View
  320. private lazy var topGradientView: UIView = {
  321. let topGradientView = UIView()
  322. topGradientView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kSafeStatusBarHeight+60)
  323. // 渐变层
  324. let bgLayer1 = CAGradientLayer()
  325. bgLayer1.colors = [UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).cgColor, UIColor(red: 0, green: 0, blue: 0, alpha: 0).cgColor]
  326. bgLayer1.locations = [0, 1]
  327. bgLayer1.frame = topGradientView.bounds
  328. bgLayer1.startPoint = CGPoint(x: 0, y: 0)
  329. bgLayer1.endPoint = CGPoint(x: 0, y: 1)
  330. topGradientView.layer.addSublayer(bgLayer1)
  331. topGradientView.layer.cornerRadius = 2;
  332. topGradientView.alpha = 1
  333. return topGradientView
  334. }()
  335. private lazy var bottomGradientView: UIView = {
  336. let bottomGradientView = UIView()
  337. bottomGradientView.frame = CGRect(x: 0, y: kScreenHeight-kSafeTabBarHeight-270, width: kScreenWidth, height: 270+kSafeTabBarHeight)
  338. let bgLayer1 = CAGradientLayer()
  339. bgLayer1.colors = [UIColor(red: 0, green: 0, blue: 0, alpha: 0.8).cgColor, UIColor(red: 0, green: 0, blue: 0, alpha: 0).cgColor]
  340. bgLayer1.locations = [0, 1]
  341. bgLayer1.frame = bottomGradientView.bounds
  342. bgLayer1.startPoint = CGPoint(x: 0, y: 1)
  343. bgLayer1.endPoint = CGPoint(x: 0, y: 0)
  344. bottomGradientView.layer.addSublayer(bgLayer1)
  345. bottomGradientView.layer.cornerRadius = 2;
  346. bottomGradientView.alpha = 1
  347. return bottomGradientView
  348. }()
  349. // MARK: 顶部导航View
  350. private lazy var navBackView: UIView = {
  351. let navBackView = UIView()
  352. navBackView.backgroundColor = UIColor.clear
  353. return navBackView
  354. }()
  355. private lazy var navBackBtn: UIButton = {
  356. let navBackBtn = UIButton(type: UIButton.ButtonType.custom)
  357. navBackBtn.setImage(kImage(name: "navbar_back_white"), for: UIControl.State.normal)
  358. navBackBtn.rx.tap.subscribe(onNext: {
  359. [weak self] (data) in
  360. if let backClosure = self?.backClosure {
  361. backClosure()
  362. }
  363. }).disposed(by: disposeBag)
  364. return navBackBtn
  365. }()
  366. private lazy var shareBtnRight: UIButton = {
  367. let shareBtnRight = UIButton(type: UIButton.ButtonType.custom)
  368. shareBtnRight.setImage(kImage(name: "nav_share_white"), for: UIControl.State.normal)
  369. shareBtnRight.rx.tap.subscribe(onNext: {
  370. [weak self] (data) in
  371. if let shareClosure = self?.shareClosure {
  372. shareClosure(self!.videoItemMdl!)
  373. }
  374. }).disposed(by: disposeBag)
  375. return shareBtnRight
  376. }()
  377. private lazy var shareBtnLeft: UIButton = {
  378. let shareBtnLeft = UIButton(type: UIButton.ButtonType.custom)
  379. shareBtnLeft.setImage(kImage(name: "nav_share_poster"), for: UIControl.State.normal)
  380. shareBtnLeft.rx.tap.subscribe(onNext: {
  381. [weak self] (data) in
  382. if let shareClosure = self?.shareClosure {
  383. shareClosure(self!.videoItemMdl!)
  384. }
  385. }).disposed(by: disposeBag)
  386. return shareBtnLeft
  387. }()
  388. // MARK: 底部View
  389. private lazy var bottomCommentView: UIView = {
  390. let bottomCommentView = UIView()
  391. bottomCommentView.backgroundColor = UIColor.clear
  392. return bottomCommentView
  393. }()
  394. private lazy var bottomSepView: UIView = {
  395. let bottomSepView = UIView()
  396. bottomSepView.backgroundColor = kffffffColor.withAlphaComponent(0.8)
  397. return bottomSepView
  398. }()
  399. private lazy var commentBtn: UIButton = {
  400. let commentBtn = UIButton(type: UIButton.ButtonType.custom)
  401. commentBtn.setTitle("0", for: UIControl.State.normal)
  402. commentBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
  403. commentBtn.setImage(kImage(name: "video_btn_note_white"), for: UIControl.State.normal)
  404. commentBtn.titleLabel?.font = kRegularFont14
  405. commentBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  406. if let buttonClickClosure = self?.buttonClickClosure {
  407. buttonClickClosure(videoBtnClickType.typeComment, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
  408. }
  409. }).disposed(by: disposeBag)
  410. return commentBtn
  411. }()
  412. private lazy var collectBtn: UIButton = {
  413. let collectBtn = UIButton(type: UIButton.ButtonType.custom)
  414. collectBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
  415. collectBtn.setImage(kImage(name: "video_btn_collect_white"), for: UIControl.State.normal)
  416. collectBtn.setImage(kImage(name: "btn_collect_pre"), for: UIControl.State.selected)
  417. collectBtn.titleLabel?.font = kRegularFont14
  418. collectBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  419. collectBtn.isSelected = !collectBtn.isSelected
  420. // 本地修改收藏数据
  421. var collectCount = self?.videoItemMdl?.collectCount ?? 0
  422. if self?.videoItemMdl?.isCollect == 0 {
  423. collectBtn.setTitle("\(collectCount)", for: .normal)
  424. collectBtn.setTitle("\(collectCount+1)", for: .selected)
  425. } else {
  426. collectBtn.setTitle("\(collectCount)", for: .selected)
  427. collectBtn.setTitle("\(collectCount-1)", for: .normal)
  428. }
  429. // 点击回调
  430. if let buttonClickClosure = self?.buttonClickClosure {
  431. buttonClickClosure(videoBtnClickType.typeCollect, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
  432. }
  433. }).disposed(by: disposeBag)
  434. return collectBtn
  435. }()
  436. private lazy var likeBtn: UIButton = {
  437. let likeBtn = UIButton(type: UIButton.ButtonType.custom)
  438. likeBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
  439. likeBtn.setImage(kImage(name: "video_btn_praise_white"), for: UIControl.State.normal)
  440. likeBtn.setImage(kImage(name: "btn_praise_pre_36px"), for: UIControl.State.selected)
  441. likeBtn.titleLabel?.font = kRegularFont14
  442. likeBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  443. likeBtn.isSelected = !likeBtn.isSelected
  444. // 本地修改点赞数据
  445. var praiseCount = self?.videoItemMdl?.praiseCount ?? 0
  446. if self?.videoItemMdl?.isLike == 0 {
  447. likeBtn.setTitle("\(praiseCount)", for: .normal)
  448. likeBtn.setTitle("\(praiseCount+1)", for: .selected)
  449. } else {
  450. likeBtn.setTitle("\(praiseCount)", for: .selected)
  451. likeBtn.setTitle("\(praiseCount-1)", for: .normal)
  452. }
  453. // 点击回调
  454. if let buttonClickClosure = self?.buttonClickClosure {
  455. buttonClickClosure(videoBtnClickType.typeLike, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
  456. }
  457. }).disposed(by: disposeBag)
  458. return likeBtn
  459. }()
  460. private lazy var commentView: UIView = {
  461. let commentView = UIView()
  462. commentView.backgroundColor = kffffffColor.withAlphaComponent(0.3)
  463. commentView.cornerRadius = 15
  464. commentView.masksToBounds = true
  465. return commentView
  466. }()
  467. private lazy var commentLabel: UILabel = {
  468. let commentLabel = UILabel()
  469. commentLabel.text = "添加评论..."
  470. commentLabel.textColor = kffffffColor
  471. commentLabel.font = kRegularFont14
  472. return commentLabel
  473. }()
  474. private lazy var textBtn: UIButton = {
  475. let textBtn = UIButton(type: UIButton.ButtonType.custom)
  476. textBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
  477. if let buttonClickClosure = self?.buttonClickClosure {
  478. buttonClickClosure(videoBtnClickType.typeComment, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
  479. }
  480. }).disposed(by: disposeBag)
  481. return textBtn
  482. }()
  483. // MARK: 话题View
  484. private lazy var topicView: CommunityVideoTopicView = {
  485. let topicView = CommunityVideoTopicView()
  486. return topicView
  487. }()
  488. // MARK: 视频内容content
  489. private lazy var contentScrollView :UIScrollView = {
  490. let contentScrollView = UIScrollView()
  491. contentScrollView.bounces = false
  492. // 设置初始contentSize
  493. contentScrollView.contentSize = CGSize.init(width: kScreenWidth-28.0, height: 44.0)
  494. contentScrollView.showsHorizontalScrollIndicator = false
  495. contentScrollView.showsVerticalScrollIndicator = false
  496. return contentScrollView
  497. }()
  498. private lazy var contentLabel: YYLabel = {
  499. let contentLabel = YYLabel()
  500. contentLabel.numberOfLines = 0;
  501. contentLabel.textColor = kffffffColor
  502. contentLabel.font = kRegularFont14
  503. return contentLabel
  504. }()
  505. // MARK: 收起展开contentのBtn
  506. private lazy var unfoldButton: UIButton = {
  507. let unfoldButton = UIButton(type: UIButton.ButtonType.custom)
  508. unfoldButton.setTitle("收起", for: .normal)
  509. unfoldButton.titleLabel?.font = kRegularFont14
  510. unfoldButton.rx.tap.subscribe(onNext: {
  511. [weak self] (data) in
  512. UIView.animate(withDuration: 0.5) {
  513. [weak self] in
  514. self?.contentScrollView.snp.remakeConstraints { (make) in
  515. make.bottom.equalTo((self?.topicView.snp_top)!)
  516. make.left.equalTo(14)
  517. make.right.equalTo(-14)
  518. make.height.equalTo(40)
  519. }
  520. self?.contentLabel.snp.remakeConstraints { (make) in
  521. make.top.left.equalToSuperview()
  522. make.width.equalTo(kScreenWidth-28)
  523. make.height.equalTo(40)
  524. }
  525. self?.bottomGradientView.frame = CGRect(x: 0, y: kScreenHeight-kSafeTabBarHeight-270, width: kScreenWidth, height: 270+kSafeTabBarHeight)
  526. }
  527. self?.unfoldButton.isHidden = true
  528. }).disposed(by: disposeBag)
  529. return unfoldButton
  530. }()
  531. // MARK: 视频Title
  532. private lazy var videoTitleLabel: UILabel = {
  533. let videoTitleLabel = UILabel()
  534. videoTitleLabel.textColor = kffffffColor
  535. videoTitleLabel.font = kMediumFont16
  536. return videoTitleLabel
  537. }()
  538. // MARK: 个人信息View
  539. private lazy var personBackView: UIView = {
  540. let personBackView = UIView()
  541. return personBackView
  542. }()
  543. private lazy var avatarButton: UIButton = {
  544. let avatarButton = UIButton(type: UIButton.ButtonType.custom)
  545. avatarButton.setImage(kImage(name: "default_avatar"), for: UIControl.State.normal)
  546. avatarButton.imageView?.contentMode = .scaleAspectFit
  547. avatarButton.cornerRadius = 15
  548. avatarButton.masksToBounds = true
  549. avatarButton.rx.tap.subscribe(onNext: {
  550. [weak self] (data) in
  551. if let buttonClickClosure = self?.buttonClickClosure {
  552. buttonClickClosure(videoBtnClickType.typePerson, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
  553. }
  554. }).disposed(by: disposeBag)
  555. return avatarButton
  556. }()
  557. private lazy var personLabel: UILabel = {
  558. let personLabel = UILabel()
  559. personLabel.textColor = kffffffColor
  560. personLabel.font = kRegularFont15
  561. return personLabel
  562. }()
  563. private lazy var followButton: UIButton = {
  564. let followButton = UIButton(type: UIButton.ButtonType.custom)
  565. followButton.titleLabel?.font = kMediumFont13
  566. followButton.layer.cornerRadius = 10
  567. followButton.layer.masksToBounds = true
  568. followButton.setTitleColor(kffffffColor, for: .normal)
  569. followButton.rx.tap.subscribe(onNext: {[weak self] (data) in
  570. if let followClosure = self?.followClosure {
  571. followClosure(self!.videoItemMdl!, followButton)
  572. }
  573. }).disposed(by: disposeBag)
  574. return followButton
  575. }()
  576. // MARK: 彩虹豆View
  577. private lazy var rainbowBeanView: UIView = {
  578. let rainbowBeanView = UIView()
  579. rainbowBeanView.backgroundColor = kRGBAColor(r: 0/255.0, g: 0/255.0, b: 0/255.0, a: 0.3)
  580. rainbowBeanView.cornerRadius = 12
  581. rainbowBeanView.masksToBounds = true
  582. return rainbowBeanView
  583. }()
  584. private lazy var beanIconImageView: UIImageView = {
  585. let beanIconImageView = UIImageView()
  586. beanIconImageView.image = kImage(name: "ico_bean_white")
  587. return beanIconImageView
  588. }()
  589. private lazy var beanLabel: UILabel = {
  590. let beanLabel = UILabel()
  591. beanLabel.textColor = kffffffColor
  592. beanLabel.font = kRegularFont13
  593. return beanLabel
  594. }()
  595. // 播放暂停icon
  596. lazy var playStatusImageView: UIImageView = {
  597. let playStatusImageView = UIImageView()
  598. playStatusImageView.image = kImage(name: "btn_pause")
  599. playStatusImageView.isHidden = true
  600. return playStatusImageView
  601. }()
  602. // MARK: - 播放动作
  603. func play() {
  604. playStatusImageView.isHidden = true
  605. videoPlayView.play()
  606. }
  607. func pause() {
  608. playStatusImageView.isHidden = false
  609. videoPlayView.pause()
  610. }
  611. @objc func videoTapAction(_ tap: UITapGestureRecognizer?) {
  612. if videoPlayView.pauseFlag {
  613. self.play()
  614. } else {
  615. self.pause()
  616. }
  617. }
  618. var videoItemMdl: CommunityVideoItemModel? {
  619. didSet {
  620. if !(self.videoItemMdl?.video == nil || self.videoItemMdl?.video == "") {
  621. videoPlayView.assetURLString = self.videoItemMdl?.video
  622. }
  623. beanLabel.text = "\(self.videoItemMdl?.willCollectBean ?? 0)彩虹豆待收获"
  624. avatarButton.kf.setImage(with: kURLImage(name: self.videoItemMdl?.avatar ?? ""), for: .normal, placeholder: kImage(name: "default_avatar"))
  625. personLabel.text = self.videoItemMdl?.username
  626. // 点赞
  627. if self.videoItemMdl?.isLike == 0 {
  628. likeBtn.setTitle("\(self.videoItemMdl?.praiseCount ?? 0)", for: .normal)
  629. } else {
  630. likeBtn.setTitle("\(self.videoItemMdl?.praiseCount ?? 0)", for: .selected)
  631. }
  632. // 收藏
  633. if self.videoItemMdl?.isCollect == 0 {
  634. collectBtn.setTitle("\(self.videoItemMdl?.collectCount ?? 0)", for: .normal)
  635. } else {
  636. collectBtn.setTitle("\(self.videoItemMdl?.collectCount ?? 0)", for: .selected)
  637. }
  638. // 评论
  639. commentBtn.setTitle("\(self.videoItemMdl?.commentCount ?? 0)", for: .normal)
  640. collectBtn.isSelected = self.videoItemMdl?.isCollect == 0 ? false : true
  641. likeBtn.isSelected = self.videoItemMdl?.isLike == 0 ? false : true
  642. if self.videoItemMdl?.uid == UserModel.shared().getModel()?.uid {
  643. followButton.isHidden = true
  644. } else {
  645. followButton.isHidden = false
  646. }
  647. CommunityFollowUserViewModel.shared.setVideoFollowType(followButton: followButton, followType: FollowType(rawValue: self.videoItemMdl?.isFollow ?? 0)!)
  648. if !(self.videoItemMdl?.title == "" || self.videoItemMdl?.title == nil) {
  649. // 有标题
  650. videoTitleLabel.text = self.videoItemMdl?.title
  651. } else {
  652. // 无标题
  653. }
  654. topicView.topicArray = self.videoItemMdl?.topic
  655. topicView.reloadData()
  656. // contentLabel.text = self.videoItemMdl?.content
  657. self.addSeeMoreButton(contentLabel, textStr: self.videoItemMdl?.content)
  658. // self.addSeeMoreButton(contentLabel, textStr: "德库尼克-快步领骑大集团,把差距控制在八分钟附近。突围集团在团结配合的同时,也在沿途的各个爬坡点展开较量。韦伦斯在德根特的帮助下,捞到26分,圆点衫无虞;贝尔哈恩、齐科内和莫里瑟积极挑战,也有分数进账。最后35公里,德根特在Col des Croix发动单飞。贝尔纳协助齐科内追击,其他突围车手则陆续掉队。在下一个爬坡点Col des Chevreres,突围集团只剩下齐科内、图恩斯、韦伦斯和莫里瑟最后四人。")
  659. self.remakeBottomConstrains()
  660. }
  661. }
  662. func remakeBottomConstrains() {
  663. let size: CGSize = contentLabel.sizeThatFits(CGSize(width: kScreenWidth-28, height: CGFloat(MAXFLOAT)))
  664. print("------size == \(size)")
  665. if size.height > 40 {
  666. // 超过2行
  667. // do nothing
  668. } else {
  669. contentScrollView.snp.remakeConstraints { (make) in
  670. make.bottom.equalTo(topicView.snp_top)
  671. make.left.equalTo(14)
  672. make.right.equalTo(-14)
  673. make.height.equalTo(size.height)
  674. }
  675. contentLabel.snp.remakeConstraints { (make) in
  676. make.top.left.equalToSuperview()
  677. make.width.equalTo(kScreenWidth-28)
  678. make.height.equalTo(size.height)
  679. }
  680. }
  681. }
  682. }