123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808 |
- //
- // CommunityVideoCoverCollectionCell.swift
- // RainbowPlanet
- //
- // Created by Christopher on 2019/7/3.
- // Copyright © 2019 RainbowPlanet. All rights reserved.
- // 视频播放列表のCell
- import UIKit
- import RxSwift
- enum videoBtnClickType {
- case typeComment
- case typeLike
- case typeCollect
- case typePerson
- }
- class CommunityVideoCoverCollectionCell: UICollectionViewCell {
-
- let disposeBag = DisposeBag()
-
- typealias BackClosure = () -> Void
- var backClosure : BackClosure?
-
- typealias ShareClosure = (_ videoItemMdl: CommunityVideoItemModel) -> Void
- var shareClosure : ShareClosure?
-
- typealias ButtonClickClosure = (_ clickType: videoBtnClickType, _ uid: Int, _ postId: Int) -> Void
- var buttonClickClosure : ButtonClickClosure?
-
- typealias FollowClosure = (_ videoItemMdl: CommunityVideoItemModel, _ button: UIButton) -> Void
- var followClosure : FollowClosure?
-
- class func cellWith(collectionView:UICollectionView,indexPath:IndexPath) -> CommunityVideoCoverCollectionCell {
- let ID = "CommunityVideoCoverCollectionCell"
- collectionView.register(CommunityVideoCoverCollectionCell.self, forCellWithReuseIdentifier: ID)
- let cell : CommunityVideoCoverCollectionCell = collectionView.dequeueReusableCell(withReuseIdentifier: ID, for: indexPath) as! CommunityVideoCoverCollectionCell
- cell.indexPath = indexPath
- return cell
- }
- //MARK: indexPath
- var indexPath: IndexPath?{
- didSet {
-
- }
- }
- //MARK: - 初始化
- override init(frame: CGRect) {
- super.init(frame: frame)
- backgroundColor = UIColor.black
- setupViews()
- setupLayouts()
- }
-
- // Neccessary - 清除待复用Cell原先的player
- override func prepareForReuse() {
- super.prepareForReuse()
-
- videoPlayView.cancelLoading()
- }
-
- required init?(coder aDecoder: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
-
- //MARK: - 设置View
- private func setupViews() {
-
- // 视频播放
- addSubview(videoPlayView)
- videoPlayView.addTapGesture(1, target: self, action: #selector(videoTapAction))
- addSubview(bottomSepView)
- addSubview(bgView)
-
- // 顶部渐变
- addSubview(topGradientView)
-
- // 顶部
- topGradientView.addSubview(navBackView)
- navBackView.addSubview(navBackBtn)
- navBackView.addSubview(shareBtnRight)
- navBackView.addSubview(shareBtnLeft)
-
- // 底部渐变
- addSubview(bottomGradientView)
- bottomGradientView.addTapGesture(1, target: self, action: #selector(videoTapAction))
-
- // 底部
- bottomGradientView.addSubview(bottomCommentView)
- bottomCommentView.addSubview(commentBtn)
- bottomCommentView.addSubview(collectBtn)
- bottomCommentView.addSubview(likeBtn)
- bottomCommentView.addSubview(commentView)
- commentView.addSubview(commentLabel)
- commentView.addSubview(textBtn)
-
- // 话题View
- bottomGradientView.addSubview(topicView)
-
- // 视频内容
- bottomGradientView.addSubview(contentScrollView)
- contentScrollView.addSubview(contentLabel)
-
- bottomGradientView.addSubview(unfoldButton)
- unfoldButton.isHidden = true
-
- // 视频标题
- bottomGradientView.addSubview(videoTitleLabel)
-
- bottomGradientView.addSubview(personBackView)
- personBackView.addSubview(avatarButton)
- personBackView.addSubview(personLabel)
- personBackView.addSubview(followButton)
-
- bottomGradientView.addSubview(rainbowBeanView)
- rainbowBeanView.addSubview(beanIconImageView)
- rainbowBeanView.addSubview(beanLabel)
-
- addSubview(playStatusImageView)
- }
-
- private func setupLayouts() {
-
- // 视频播放
- videoPlayView.snp.makeConstraints { (make) in
- make.edges.equalToSuperview()
- }
-
- // 顶部
- navBackView.snp.makeConstraints { (make) in
- make.top.equalTo(kSafeStatusBarHeight)
- make.left.right.equalToSuperview()
- make.height.equalTo(44)
- }
- navBackBtn.snp.makeConstraints { (make) in
- make.left.equalTo(5)
- make.centerY.equalToSuperview()
- make.size.equalTo(40)
- }
- shareBtnRight.snp.makeConstraints { (make) in
- make.right.equalTo(-6)
- make.centerY.equalToSuperview()
- make.size.equalTo(39)
- }
- shareBtnLeft.snp.makeConstraints { (make) in
- make.right.equalTo(-52)
- make.bottom.equalTo(-8)
- make.width.equalTo(123)
- make.height.equalTo(35)
- }
-
- // 底部
- bottomCommentView.snp.makeConstraints { (make) in
- make.bottom.equalTo(-kSafeTabBarHeight)
- make.left.right.equalToSuperview()
- make.height.equalTo(60)
- }
- bottomSepView.snp.makeConstraints { (make) in
- make.left.right.equalToSuperview()
- make.height.equalTo(0.5)
- make.bottom.equalToSuperview().offset(-(kSafeTabBarHeight + 60))
- }
-
- commentBtn.snp.makeConstraints { (make) in
- make.right.equalToSuperview().offset(-14)
- make.centerY.equalToSuperview()
- make.height.equalTo(24)
- }
- commentBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
-
- collectBtn.snp.makeConstraints { (make) in
- make.right.equalTo(commentBtn.snp_left).offset(-15)
- make.centerY.equalToSuperview()
- make.height.equalTo(37)
- }
- collectBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
-
- likeBtn.snp.makeConstraints { (make) in
- make.right.equalTo(collectBtn.snp_left).offset(-15)
- make.centerY.equalToSuperview()
- make.height.equalTo(37)
- }
- likeBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 5)
-
- commentView.snp.makeConstraints { (make) in
- make.centerY.equalToSuperview()
- make.left.equalToSuperview().offset(14)
- make.right.equalTo(likeBtn.snp_left).offset(-10)
- make.height.equalTo(30)
- }
- commentLabel.snp.makeConstraints { (make) in
- make.left.equalTo(15)
- make.centerY.equalToSuperview()
- make.width.equalTo(70)
- make.height.equalTo(28)
- }
- textBtn.snp.makeConstraints { (make) in
- make.edges.equalToSuperview()
- }
-
- // 话题View
- topicView.snp.makeConstraints { (make) in
- make.bottom.equalTo(bottomCommentView.snp_top)
- make.left.right.equalToSuperview()
- make.height.equalTo(45)
- }
-
- // 视频内容
- contentScrollView.snp.makeConstraints { (make) in
- make.bottom.equalTo(topicView.snp_top)
- make.left.equalTo(14)
- make.right.equalTo(-14)
- make.height.equalTo(44)
- }
-
- contentLabel.snp.makeConstraints { (make) in
- make.top.left.equalToSuperview()
- make.width.equalTo(kScreenWidth-28)
- make.height.equalTo(44)
- }
-
- // 视频标题
- videoTitleLabel.snp.makeConstraints { (make) in
- make.left.equalTo(14)
- make.right.equalTo(-14)
- make.height.equalTo(23)
- make.bottom.equalTo(contentScrollView.snp_top).offset(-10)
- }
-
- // personView
- personBackView.snp.makeConstraints { (make) in
- make.left.equalTo(14)
- make.height.equalTo(30)
- make.bottom.equalTo(videoTitleLabel.snp_top).offset(-20)
- }
- avatarButton.snp.makeConstraints { (make) in
- make.left.top.equalToSuperview()
- make.size.equalTo(30)
- }
- personLabel.snp.makeConstraints { (make) in
- make.left.equalTo(avatarButton.snp_right).offset(10)
- make.centerY.equalToSuperview()
- make.height.equalTo(18)
- }
- followButton.snp.makeConstraints { (make) in
- make.left.equalTo(personLabel.snp_right).offset(10)
- make.centerY.equalToSuperview()
- make.width.equalTo(64)
- make.height.equalTo(20)
- make.right.equalToSuperview()
- }
-
- // 彩虹豆View
- rainbowBeanView.snp.makeConstraints { (make) in
- make.left.equalTo(14)
- make.height.equalTo(24)
- make.bottom.equalTo(personBackView.snp_top).offset(-10)
- }
- // rainbowBeanView.snp.makeConstraints { (make) in
- // make.top.equalTo(10)
- // make.left.equalTo(14)
- // make.height.equalTo(24)
- // make.bottom.equalTo(personBackView.snp_top).offset(-10)
- // }
- beanIconImageView.snp.makeConstraints { (make) in
- make.left.equalTo(6)
- make.centerY.equalToSuperview()
- make.size.equalTo(19)
- }
- beanLabel.snp.makeConstraints { (make) in
- make.left.equalTo(beanIconImageView.snp_right).offset(5)
- make.top.bottom.equalToSuperview()
- make.right.equalTo(-6)
- }
-
- //
- playStatusImageView.snp.makeConstraints { (make) in
- make.center.equalToSuperview()
- make.width.equalTo(50)
- make.height.equalTo(60)
- }
-
- }
-
- func addSeeMoreButton(_ label: YYLabel, textStr: String?) {
- label.attributedText = NSAttributedString(string: textStr ?? "", attributes: [
- NSAttributedString.Key.foregroundColor: kffffffColor,
- NSAttributedString.Key.font: kRegularFont14!
- ])
-
- let moreString = " 展开"
- let text = NSMutableAttributedString(string: "... \(moreString)")
- let expandRange = (text.string as NSString).range(of: moreString)
-
- text.addAttribute(.foregroundColor, value: kffffffColor, range: expandRange)
- text.addAttribute(.font, value: kMediumFont24!, range: expandRange)
- text.addAttribute(.foregroundColor, value: kffffffColor, range: NSRange(location: 0, length: expandRange.location))
-
- //添加点击事件
- let hi = YYTextHighlight()
- text.yy_setTextHighlight(hi, range: (text.string as NSString).range(of: moreString))
- hi.tapAction = {
- [weak self] (containerView, text, range, rect) in
- //点击展开
- self?.setTextFrame(true)
- }
-
- text.yy_font = kRegularFont14
-
- let seeMore = YYLabel()
- seeMore.attributedText = text
- seeMore.sizeToFit()
-
- let truncationToken = NSAttributedString.yy_attachmentString(withContent: seeMore, contentMode: UIView.ContentMode.center, attachmentSize: seeMore.frame.size, alignTo: text.yy_font!, alignment: YYTextVerticalAlignment.top)
-
- label.truncationToken = truncationToken
- }
-
- func setTextFrame(_ isExpand: Bool) {
- if isExpand {
- expandString()
-
- let size: CGSize = contentLabel.sizeThatFits(CGSize(width: kScreenWidth-28, height: CGFloat(MAXFLOAT)))
- print("------size == \(size)")
-
- contentScrollView.snp.remakeConstraints { (make) in
- make.bottom.equalTo(topicView.snp_top).offset(-40)
- make.left.equalTo(14)
- make.right.equalTo(-14)
- make.height.equalTo(size.height)
- }
- contentLabel.snp.remakeConstraints { (make) in
- make.top.left.equalToSuperview()
- make.width.equalTo(kScreenWidth-28)
- make.height.equalTo(size.height)
- }
-
- unfoldButton.snp.remakeConstraints { (make) in
- make.bottom.equalTo(topicView.snp_top).offset(-10)
- make.right.equalTo(-4)
- make.width.equalTo(48)
- make.height.equalTo(20)
- }
- unfoldButton.isHidden = false
-
- // 控件高度+间距+"收起"の高度
- let backHeight = (60+45+size.height+23+30+24) + (10+20+10+20) + 40
- UIView.animate(withDuration: 0.5) {
- [weak self] in
-
- self?.bottomGradientView.frame = CGRect(x: 0, y: kScreenHeight-backHeight-kSafeTabBarHeight, width: kScreenWidth, height: backHeight+kSafeTabBarHeight)
- }
- } else {
- // contentScrollView.frame = CGRect(x: 14, y: 0, width: UIScreen.main.bounds.size.width - 28, height: 30)
- // contentLabel.frame = CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width - 40, height: 30)
- }
- }
-
- func expandString() {
- let attri = contentLabel.attributedText as? NSMutableAttributedString
- contentLabel.attributedText = attri
- }
-
- lazy var bgView: UIView = {
- let bgView = UIView(frame: self.frame)
- bgView.backgroundColor = UIColor(hexString: "000000", alpha: 0.1)
- bgView.isUserInteractionEnabled = true
- return bgView
- }()
-
- // MARK: 视频播放View
- private lazy var videoPlayView: CommunityVideoPlayView = {
- let videoPlayView = CommunityVideoPlayView()
- videoPlayView.isUserInteractionEnabled = true
- return videoPlayView
- }()
-
- // MARK: 渐变View
- private lazy var topGradientView: UIView = {
- let topGradientView = UIView()
- topGradientView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kSafeStatusBarHeight+60)
- // 渐变层
- let bgLayer1 = CAGradientLayer()
- bgLayer1.colors = [UIColor(red: 0, green: 0, blue: 0, alpha: 0.5).cgColor, UIColor(red: 0, green: 0, blue: 0, alpha: 0).cgColor]
- bgLayer1.locations = [0, 1]
- bgLayer1.frame = topGradientView.bounds
- bgLayer1.startPoint = CGPoint(x: 0, y: 0)
- bgLayer1.endPoint = CGPoint(x: 0, y: 1)
- topGradientView.layer.addSublayer(bgLayer1)
- topGradientView.layer.cornerRadius = 2;
- topGradientView.alpha = 1
- return topGradientView
- }()
-
- private lazy var bottomGradientView: UIView = {
- let bottomGradientView = UIView()
- bottomGradientView.frame = CGRect(x: 0, y: kScreenHeight-kSafeTabBarHeight-270, width: kScreenWidth, height: 270+kSafeTabBarHeight)
- let bgLayer1 = CAGradientLayer()
- bgLayer1.colors = [UIColor(red: 0, green: 0, blue: 0, alpha: 0.8).cgColor, UIColor(red: 0, green: 0, blue: 0, alpha: 0).cgColor]
- bgLayer1.locations = [0, 1]
- bgLayer1.frame = bottomGradientView.bounds
- bgLayer1.startPoint = CGPoint(x: 0, y: 1)
- bgLayer1.endPoint = CGPoint(x: 0, y: 0)
- bottomGradientView.layer.addSublayer(bgLayer1)
- bottomGradientView.layer.cornerRadius = 2;
- bottomGradientView.alpha = 1
- return bottomGradientView
- }()
-
-
- // MARK: 顶部导航View
- private lazy var navBackView: UIView = {
- let navBackView = UIView()
- navBackView.backgroundColor = UIColor.clear
- return navBackView
- }()
-
- private lazy var navBackBtn: UIButton = {
- let navBackBtn = UIButton(type: UIButton.ButtonType.custom)
- navBackBtn.setImage(kImage(name: "navbar_back_white"), for: UIControl.State.normal)
- navBackBtn.rx.tap.subscribe(onNext: {
- [weak self] (data) in
- if let backClosure = self?.backClosure {
- backClosure()
- }
- }).disposed(by: disposeBag)
- return navBackBtn
- }()
-
- private lazy var shareBtnRight: UIButton = {
- let shareBtnRight = UIButton(type: UIButton.ButtonType.custom)
- shareBtnRight.setImage(kImage(name: "nav_share_white"), for: UIControl.State.normal)
- shareBtnRight.rx.tap.subscribe(onNext: {
- [weak self] (data) in
- if let shareClosure = self?.shareClosure {
- shareClosure(self!.videoItemMdl!)
- }
- }).disposed(by: disposeBag)
- return shareBtnRight
- }()
-
- private lazy var shareBtnLeft: UIButton = {
- let shareBtnLeft = UIButton(type: UIButton.ButtonType.custom)
- shareBtnLeft.setImage(kImage(name: "nav_share_poster"), for: UIControl.State.normal)
- shareBtnLeft.rx.tap.subscribe(onNext: {
- [weak self] (data) in
- if let shareClosure = self?.shareClosure {
- shareClosure(self!.videoItemMdl!)
- }
- }).disposed(by: disposeBag)
- return shareBtnLeft
- }()
-
- // MARK: 底部View
- private lazy var bottomCommentView: UIView = {
- let bottomCommentView = UIView()
- bottomCommentView.backgroundColor = UIColor.clear
- return bottomCommentView
- }()
-
- private lazy var bottomSepView: UIView = {
- let bottomSepView = UIView()
- bottomSepView.backgroundColor = kffffffColor.withAlphaComponent(0.8)
- return bottomSepView
- }()
-
- private lazy var commentBtn: UIButton = {
- let commentBtn = UIButton(type: UIButton.ButtonType.custom)
- commentBtn.setTitle("0", for: UIControl.State.normal)
- commentBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
- commentBtn.setImage(kImage(name: "video_btn_note_white"), for: UIControl.State.normal)
- commentBtn.titleLabel?.font = kRegularFont14
- commentBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
- if let buttonClickClosure = self?.buttonClickClosure {
- buttonClickClosure(videoBtnClickType.typeComment, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
- }
- }).disposed(by: disposeBag)
- return commentBtn
- }()
-
- private lazy var collectBtn: UIButton = {
- let collectBtn = UIButton(type: UIButton.ButtonType.custom)
- collectBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
- collectBtn.setImage(kImage(name: "video_btn_collect_white"), for: UIControl.State.normal)
- collectBtn.setImage(kImage(name: "btn_collect_pre"), for: UIControl.State.selected)
- collectBtn.titleLabel?.font = kRegularFont14
- collectBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
- collectBtn.isSelected = !collectBtn.isSelected
- // 本地修改收藏数据
- var collectCount = self?.videoItemMdl?.collectCount ?? 0
- if self?.videoItemMdl?.isCollect == 0 {
- collectBtn.setTitle("\(collectCount)", for: .normal)
- collectBtn.setTitle("\(collectCount+1)", for: .selected)
- } else {
- collectBtn.setTitle("\(collectCount)", for: .selected)
- collectBtn.setTitle("\(collectCount-1)", for: .normal)
- }
- // 点击回调
- if let buttonClickClosure = self?.buttonClickClosure {
- buttonClickClosure(videoBtnClickType.typeCollect, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
- }
- }).disposed(by: disposeBag)
- return collectBtn
- }()
-
- private lazy var likeBtn: UIButton = {
- let likeBtn = UIButton(type: UIButton.ButtonType.custom)
- likeBtn.setTitleColor(kffffffColor, for: UIControl.State.normal)
- likeBtn.setImage(kImage(name: "video_btn_praise_white"), for: UIControl.State.normal)
- likeBtn.setImage(kImage(name: "btn_praise_pre_36px"), for: UIControl.State.selected)
- likeBtn.titleLabel?.font = kRegularFont14
- likeBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
- likeBtn.isSelected = !likeBtn.isSelected
- // 本地修改点赞数据
- var praiseCount = self?.videoItemMdl?.praiseCount ?? 0
- if self?.videoItemMdl?.isLike == 0 {
- likeBtn.setTitle("\(praiseCount)", for: .normal)
- likeBtn.setTitle("\(praiseCount+1)", for: .selected)
- } else {
- likeBtn.setTitle("\(praiseCount)", for: .selected)
- likeBtn.setTitle("\(praiseCount-1)", for: .normal)
- }
- // 点击回调
- if let buttonClickClosure = self?.buttonClickClosure {
- buttonClickClosure(videoBtnClickType.typeLike, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
- }
- }).disposed(by: disposeBag)
- return likeBtn
- }()
-
- private lazy var commentView: UIView = {
- let commentView = UIView()
- commentView.backgroundColor = kffffffColor.withAlphaComponent(0.3)
- commentView.cornerRadius = 15
- commentView.masksToBounds = true
- return commentView
- }()
-
- private lazy var commentLabel: UILabel = {
- let commentLabel = UILabel()
- commentLabel.text = "添加评论..."
- commentLabel.textColor = kffffffColor
- commentLabel.font = kRegularFont14
- return commentLabel
- }()
-
- private lazy var textBtn: UIButton = {
- let textBtn = UIButton(type: UIButton.ButtonType.custom)
- textBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
- if let buttonClickClosure = self?.buttonClickClosure {
- buttonClickClosure(videoBtnClickType.typeComment, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
- }
- }).disposed(by: disposeBag)
- return textBtn
- }()
-
- // MARK: 话题View
- private lazy var topicView: CommunityVideoTopicView = {
- let topicView = CommunityVideoTopicView()
- return topicView
- }()
-
- // MARK: 视频内容content
- private lazy var contentScrollView :UIScrollView = {
- let contentScrollView = UIScrollView()
- contentScrollView.bounces = false
- // 设置初始contentSize
- contentScrollView.contentSize = CGSize.init(width: kScreenWidth-28.0, height: 44.0)
- contentScrollView.showsHorizontalScrollIndicator = false
- contentScrollView.showsVerticalScrollIndicator = false
- return contentScrollView
- }()
-
- private lazy var contentLabel: YYLabel = {
- let contentLabel = YYLabel()
- contentLabel.numberOfLines = 0;
- contentLabel.textColor = kffffffColor
- contentLabel.font = kRegularFont14
- return contentLabel
- }()
-
- // MARK: 收起展开contentのBtn
- private lazy var unfoldButton: UIButton = {
- let unfoldButton = UIButton(type: UIButton.ButtonType.custom)
- unfoldButton.setTitle("收起", for: .normal)
- unfoldButton.titleLabel?.font = kRegularFont14
- unfoldButton.rx.tap.subscribe(onNext: {
- [weak self] (data) in
-
- UIView.animate(withDuration: 0.5) {
- [weak self] in
- self?.contentScrollView.snp.remakeConstraints { (make) in
- make.bottom.equalTo((self?.topicView.snp_top)!)
- make.left.equalTo(14)
- make.right.equalTo(-14)
- make.height.equalTo(40)
- }
-
- self?.contentLabel.snp.remakeConstraints { (make) in
- make.top.left.equalToSuperview()
- make.width.equalTo(kScreenWidth-28)
- make.height.equalTo(40)
- }
-
- self?.bottomGradientView.frame = CGRect(x: 0, y: kScreenHeight-kSafeTabBarHeight-270, width: kScreenWidth, height: 270+kSafeTabBarHeight)
- }
-
- self?.unfoldButton.isHidden = true
-
- }).disposed(by: disposeBag)
- return unfoldButton
- }()
-
- // MARK: 视频Title
- private lazy var videoTitleLabel: UILabel = {
- let videoTitleLabel = UILabel()
- videoTitleLabel.textColor = kffffffColor
- videoTitleLabel.font = kMediumFont16
- return videoTitleLabel
- }()
-
- // MARK: 个人信息View
- private lazy var personBackView: UIView = {
- let personBackView = UIView()
- return personBackView
- }()
-
- private lazy var avatarButton: UIButton = {
- let avatarButton = UIButton(type: UIButton.ButtonType.custom)
- avatarButton.setImage(kImage(name: "default_avatar"), for: UIControl.State.normal)
- avatarButton.imageView?.contentMode = .scaleAspectFit
- avatarButton.cornerRadius = 15
- avatarButton.masksToBounds = true
- avatarButton.rx.tap.subscribe(onNext: {
- [weak self] (data) in
- if let buttonClickClosure = self?.buttonClickClosure {
- buttonClickClosure(videoBtnClickType.typePerson, self?.videoItemMdl?.uid ?? 0, self?.videoItemMdl?.id ?? 0)
- }
- }).disposed(by: disposeBag)
- return avatarButton
- }()
-
- private lazy var personLabel: UILabel = {
- let personLabel = UILabel()
- personLabel.textColor = kffffffColor
- personLabel.font = kRegularFont15
- return personLabel
- }()
-
- private lazy var followButton: UIButton = {
- let followButton = UIButton(type: UIButton.ButtonType.custom)
- followButton.titleLabel?.font = kMediumFont13
- followButton.layer.cornerRadius = 10
- followButton.layer.masksToBounds = true
- followButton.setTitleColor(kffffffColor, for: .normal)
- followButton.rx.tap.subscribe(onNext: {[weak self] (data) in
- if let followClosure = self?.followClosure {
- followClosure(self!.videoItemMdl!, followButton)
- }
- }).disposed(by: disposeBag)
- return followButton
- }()
-
- // MARK: 彩虹豆View
- private lazy var rainbowBeanView: UIView = {
- let rainbowBeanView = UIView()
- rainbowBeanView.backgroundColor = kRGBAColor(r: 0/255.0, g: 0/255.0, b: 0/255.0, a: 0.3)
- rainbowBeanView.cornerRadius = 12
- rainbowBeanView.masksToBounds = true
- return rainbowBeanView
- }()
-
- private lazy var beanIconImageView: UIImageView = {
- let beanIconImageView = UIImageView()
- beanIconImageView.image = kImage(name: "ico_bean_white")
- return beanIconImageView
- }()
-
- private lazy var beanLabel: UILabel = {
- let beanLabel = UILabel()
- beanLabel.textColor = kffffffColor
- beanLabel.font = kRegularFont13
- return beanLabel
- }()
-
- // 播放暂停icon
- lazy var playStatusImageView: UIImageView = {
- let playStatusImageView = UIImageView()
- playStatusImageView.image = kImage(name: "btn_pause")
- playStatusImageView.isHidden = true
- return playStatusImageView
- }()
-
-
-
- // MARK: - 播放动作
- func play() {
- playStatusImageView.isHidden = true
- videoPlayView.play()
- }
-
- func pause() {
- playStatusImageView.isHidden = false
- videoPlayView.pause()
- }
-
- @objc func videoTapAction(_ tap: UITapGestureRecognizer?) {
- if videoPlayView.pauseFlag {
- self.play()
- } else {
- self.pause()
- }
- }
-
- var videoItemMdl: CommunityVideoItemModel? {
- didSet {
- if !(self.videoItemMdl?.video == nil || self.videoItemMdl?.video == "") {
- videoPlayView.assetURLString = self.videoItemMdl?.video
- }
-
- beanLabel.text = "\(self.videoItemMdl?.willCollectBean ?? 0)彩虹豆待收获"
-
-
- avatarButton.kf.setImage(with: kURLImage(name: self.videoItemMdl?.avatar ?? ""), for: .normal, placeholder: kImage(name: "default_avatar"))
- personLabel.text = self.videoItemMdl?.username
-
- // 点赞
- if self.videoItemMdl?.isLike == 0 {
- likeBtn.setTitle("\(self.videoItemMdl?.praiseCount ?? 0)", for: .normal)
- } else {
- likeBtn.setTitle("\(self.videoItemMdl?.praiseCount ?? 0)", for: .selected)
- }
- // 收藏
- if self.videoItemMdl?.isCollect == 0 {
- collectBtn.setTitle("\(self.videoItemMdl?.collectCount ?? 0)", for: .normal)
- } else {
- collectBtn.setTitle("\(self.videoItemMdl?.collectCount ?? 0)", for: .selected)
- }
- // 评论
- commentBtn.setTitle("\(self.videoItemMdl?.commentCount ?? 0)", for: .normal)
-
- collectBtn.isSelected = self.videoItemMdl?.isCollect == 0 ? false : true
- likeBtn.isSelected = self.videoItemMdl?.isLike == 0 ? false : true
-
-
- if self.videoItemMdl?.uid == UserModel.shared().getModel()?.uid {
- followButton.isHidden = true
- } else {
- followButton.isHidden = false
- }
- CommunityFollowUserViewModel.shared.setVideoFollowType(followButton: followButton, followType: FollowType(rawValue: self.videoItemMdl?.isFollow ?? 0)!)
-
- if !(self.videoItemMdl?.title == "" || self.videoItemMdl?.title == nil) {
- // 有标题
- videoTitleLabel.text = self.videoItemMdl?.title
-
- } else {
- // 无标题
-
- }
-
- topicView.topicArray = self.videoItemMdl?.topic
- topicView.reloadData()
-
- // contentLabel.text = self.videoItemMdl?.content
-
- self.addSeeMoreButton(contentLabel, textStr: self.videoItemMdl?.content)
-
- // self.addSeeMoreButton(contentLabel, textStr: "德库尼克-快步领骑大集团,把差距控制在八分钟附近。突围集团在团结配合的同时,也在沿途的各个爬坡点展开较量。韦伦斯在德根特的帮助下,捞到26分,圆点衫无虞;贝尔哈恩、齐科内和莫里瑟积极挑战,也有分数进账。最后35公里,德根特在Col des Croix发动单飞。贝尔纳协助齐科内追击,其他突围车手则陆续掉队。在下一个爬坡点Col des Chevreres,突围集团只剩下齐科内、图恩斯、韦伦斯和莫里瑟最后四人。")
-
- self.remakeBottomConstrains()
- }
- }
-
- func remakeBottomConstrains() {
-
- let size: CGSize = contentLabel.sizeThatFits(CGSize(width: kScreenWidth-28, height: CGFloat(MAXFLOAT)))
- print("------size == \(size)")
-
- if size.height > 40 {
- // 超过2行
- // do nothing
-
- } else {
-
- contentScrollView.snp.remakeConstraints { (make) in
- make.bottom.equalTo(topicView.snp_top)
- make.left.equalTo(14)
- make.right.equalTo(-14)
- make.height.equalTo(size.height)
- }
-
- contentLabel.snp.remakeConstraints { (make) in
- make.top.left.equalToSuperview()
- make.width.equalTo(kScreenWidth-28)
- make.height.equalTo(size.height)
- }
- }
-
-
-
-
- }
-
- }
|