123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348 |
- //
- // GXBannerTestCell.swift
- // GXBannerSample
- //
- // Created by Gin on 2020/7/24.
- // Copyright © 2020 gin. All rights reserved.
- //
- import BFFramework
- import UIKit
- class MVBannerCell: UICollectionViewCell {
- // 做同款
- var reCreateBtnClicHandle: ((_ sender: UIButton, _ videoInfo: PQVideoListModel?) -> Void)?
- var sharedBtnClicHandle: ((_ type:Int) -> Void)?
- let musicWidth: CGFloat = (9.0 / 16.0 * (cScreenHeigth - (cDevice_iPhoneStatusBarHei + 45 + 60 + (cDefaultMargin * 2 + cSafeAreaHeight) + cDefaultMargin * 3 + 15))) - 15 - (16 + cDefaultMargin) * 2 - (10 + 106 + 10)
- // 封面
- lazy var converView: UIImageView = {
- let iv = UIImageView()
- iv.contentMode = .scaleAspectFill
- iv.clipsToBounds = true
- iv.addCorner(corner: 8)
- return iv
- }()
- lazy var progressView: UIProgressView = {
- let progressView = UIProgressView(progressViewStyle: .default)
- progressView.progressTintColor = .white
- return progressView
- }()
- // lazy var backShadowView: UIView = {
- // let backShowView = UIView()
- // backShowView.layer.masksToBounds = false
- // backShowView.layer.shadowColor = UIColor.black.cgColor
- // backShowView.layer.shadowOpacity = 0.3 // 设置阴影的透明度
- // backShowView.layer.shadowRadius = 4
- // backShowView.layer.shadowOffset = CGSize(width: 0, height: 4) // 设置阴影的偏移量
- // return backShowView
- // }()
- // 下面 marks view
- lazy var bottmMaskView: UIImageView = {
- let bottmMaskView = UIImageView(image: UIImage(named: "home_marks"))
- bottmMaskView.isUserInteractionEnabled = true
- bottmMaskView.addCorner(corner: 8)
- return bottmMaskView
- }()
- // 暂停view
- lazy var pauseView: UIImageView = {
- let pauseView = UIImageView(image: UIImage(named: "video_pause"))
- pauseView.isHidden = false
- return pauseView
- }()
- /// 音乐内容view
- lazy var musicContenView: UIView = {
- let musicContenView = UIView()
- return musicContenView
- }()
- // 音乐图片
- lazy var musicImageView: UIImageView = {
- let musicImageView = UIImageView(image: UIImage(named: "musicName_icon"))
- musicImageView.showLoadingAnimation(duration: 3)
- return musicImageView
- }()
- // 音乐背景
- lazy var musicBgView: UIImageView = {
- let musicBgView = UIImageView(image: UIImage(named: "musicName_bg"))
- return musicBgView
- }()
-
- /// 标题
- lazy var titleLabel: UILabel = {
- let titleLabel = UILabel()
- titleLabel.textAlignment = .left
- titleLabel.textColor = .white
- titleLabel.numberOfLines = 0
- titleLabel.lineBreakMode = .byCharWrapping
- titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
- titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .bold)
- return titleLabel
- }()
- /// 音乐歌曲名称
- lazy var musicNameLab: LMJHorizontalScrollText = {
- let musicNameLab = LMJHorizontalScrollText(frame: CGRect(x: 12 + cDefaultMargin, y: 0, width: musicWidth, height: 32))
- musicNameLab.textColor = UIColor.white
- musicNameLab.textFont = UIFont.systemFont(ofSize: 15, weight: .semibold)
- musicNameLab.speed = 0.03
- musicNameLab.moveDirection = LMJTextScrollMoveLeft
- musicNameLab.moveMode = LMJTextScrollContinuous
- musicNameLab.stop()
- return musicNameLab
- }()
- lazy var reCreateBtn: UIButton = {
- let reCreateBtn = UIButton(type: .custom)
- reCreateBtn.setTitle(" 做同款", for: .normal)
- reCreateBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .semibold)
- reCreateBtn.setTitleColor(UIColor.white, for: .normal)
- reCreateBtn.addCorner(corner: 8)
- reCreateBtn.setImage(UIImage(named: "reCreate"), for: .normal)
- reCreateBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
- reCreateBtn.backgroundColor = UIColor(red: 61.0 / 255.0, green: 193.0 / 255.0, blue: 193.0 / 255.0, alpha: 1)
- reCreateBtn.eventInterval = 0.5
- return reCreateBtn
- }()
- // 视频分类
- lazy var typeImage: UIImageView = {
- let typeImage = UIImageView(image: UIImage(named: "categary_icon"))
- return typeImage
- }()
- // 视频分类
- lazy var typeLab: UILabel = {
- let typeLab = UILabel()
- typeLab.font = UIFont.systemFont(ofSize: 14, weight: .semibold)
- typeLab.textColor = UIColor.white
- return typeLab
- }()
-
- lazy var usageAmountL:MVBannerUsageView = {
- let v = MVBannerUsageView()
- return v
- }()
-
- lazy var friendIV:UIButton = {
- // let iv = UIImageView(image: UIImage(named: "b_pyq"))
- let iv = UIButton(type: .custom)
- iv.setImage(UIImage(named: "b_pyq"), for: .normal)
- iv.tag = 2201
- iv.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
- // iv.layer.backgroundColor = UIColor.black.cgColor
- // iv.layer.cornerRadius = 22
- // iv.alpha = 0.3
- return iv
- }()
- lazy var wxIV:UIButton = {
- // let iv = UIImageView(image: UIImage(named: "b_wx"))
- let iv = UIButton(type: .custom)
- iv.setImage(UIImage(named: "b_wx"), for: .normal)
- iv.tag = 2202
- iv.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
- // iv.layer.backgroundColor = UIColor.black.cgColor
- // iv.layer.cornerRadius = 22
- // iv.alpha = 0.3
- return iv
- }()
-
- override func prepareForReuse() {
- musicNameLab.stop()
- }
- var videoData: PQVideoListModel? {
- didSet {
- addLayout()
- addData()
-
- }
- }
- override func layoutSubviews() {
- super.layoutSubviews()
- }
- override init(frame: CGRect) {
- super.init(frame: frame)
- // contentView.addSubview(backShadowView)
- contentView.addSubview(converView)
- contentView.addSubview(bottmMaskView)
- contentView.addSubview(pauseView)
- bottmMaskView.addSubview(progressView)
- // bottmMaskView.addSubview(typeImage)
- // bottmMaskView.addSubview(typeLab)
- bottmMaskView.addSubview(titleLabel)
- bottmMaskView.addSubview(usageAmountL)
- bottmMaskView.addSubview(friendIV)
- bottmMaskView.addSubview(wxIV)
-
- bottmMaskView.addSubview(reCreateBtn)
- bottmMaskView.addSubview(musicContenView)
- musicContenView.addSubview(musicBgView)
- musicContenView.addSubview(musicImageView)
- musicBgView.addSubview(musicNameLab)
- }
- func addData() {
- typeLab.text = "\(videoData?.categoryName ?? "")"
- BFLog(message: "videoDatavideoData \(String(describing: videoData?.title))")
-
- let textSize = sizeWithText(text: videoData?.title ?? "", font: UIFont.systemFont(ofSize: 16, weight: .bold), size: CGSize.init(width: self.frame.width - 24, height: CGFloat.greatestFiniteMagnitude))
-
- BFLog(message: "XXXXXXX videoData?.title is \(String(describing: videoData?.title)) height \(textSize.height) width is \(adapterWidth(width: 300))")
- BFLog(message: "videoData?.title is \(String(describing: videoData?.title)) height \(textSize.height)")
- titleLabel.text = videoData?.title ?? ""
-
- // if videoData?.categoryImage != nil {
- // typeImage.setNetImage(url: "\(videoData?.categoryImage ?? "")", placeholder: UIImage(named: "categary_icon")!)
- // } else {
- // typeImage.image = UIImage(named: "categary_icon")
- // }
- usageAmountL.amount = videoData?.reCreateVideoData?.reProduceCount ?? 0
-
- let coverImg = (videoData?.videoCoverSnapshotPath != nil && (videoData?.videoCoverSnapshotPath?.count ?? 0) > 0) ? videoData?.videoCoverSnapshotPath ?? "" : (videoData?.coverImg?["coverImgPath"] as? String ?? "")
- BFLog(message: "coverImg url is \(coverImg)")
- netImage(url: coverImg, mainView: converView)
- let nameWidth: CGFloat = sizeWithText(text: "\(videoData?.reCreateVideoData?.rhythmMusicName ?? "") ", font: UIFont.systemFont(ofSize: 15, weight: .semibold), size: CGSize(width: cScreenWidth, height: 32)).width
- musicNameLab.stop()
- if nameWidth > musicWidth {
- musicNameLab.move()
- musicNameLab.text = "\(videoData?.reCreateVideoData?.rhythmMusicName ?? "") "
- } else {
- musicNameLab.stop()
- musicNameLab.text = "\(videoData?.reCreateVideoData?.rhythmMusicName ?? "") "
- }
- }
- ///
- /// - Returns: <#description#>
- func addLayout() {
- // backShadowView.snp.remakeConstraints { make in
- // make.width.equalToSuperview()
- // make.height.equalToSuperview()
- // make.left.equalToSuperview()
- // make.top.equalToSuperview()
- // }
- converView.snp.remakeConstraints { make in
- make.left.bottom.top.right.equalToSuperview()
- }
- pauseView.snp.remakeConstraints { make in
- make.width.equalTo(82)
- make.height.equalTo(82)
- make.center.equalToSuperview()
- }
-
-
- bottmMaskView.snp.remakeConstraints { make in
- make.width.equalToSuperview()
- make.height.equalTo(150 + 100)
- make.left.equalToSuperview()
- make.bottom.equalToSuperview()
- }
- progressView.snp.remakeConstraints { make in
- make.height.equalTo(2)
- make.left.equalToSuperview().offset(3)
- make.right.equalToSuperview().offset(-3)
- make.bottom.equalToSuperview()
- }
- reCreateBtn.snp.remakeConstraints { make in
- make.width.equalTo(106)
- make.height.equalTo(46)
- make.right.equalToSuperview().offset(-cDefaultMargin)
- make.bottom.equalTo(progressView.snp.top).offset(-cDefaultMargin * 2)
- }
- musicContenView.snp.remakeConstraints { make in
- make.centerY.equalTo(reCreateBtn)
- make.height.equalTo(32)
- make.right.equalTo(reCreateBtn.snp.left).offset(-cDefaultMargin)
- make.left.equalToSuperview().offset(cDefaultMargin)
- }
- musicImageView.snp.makeConstraints { make in
- make.top.left.equalToSuperview()
- make.width.height.equalTo(musicContenView.snp.height)
- }
- musicBgView.snp.makeConstraints { make in
- make.left.equalTo(musicImageView.snp.centerX)
- make.right.top.height.equalToSuperview()
- }
-
- titleLabel.snp.remakeConstraints { make in
- make.width.equalToSuperview().offset(-24)
- // make.height.equalTo(textSize.height + 2)
- make.left.equalToSuperview().offset(12)
- make.bottom.equalTo(musicContenView.snp.top).offset(-cDefaultMargin - 2)
- }
- // if(videoData?.title?.count ?? 0 > 0){
- // typeImage.snp.remakeConstraints { make in
- // make.left.equalTo(musicContenView.snp.left)
- // make.height.width.equalTo(18)
- // make.bottom.equalTo(titleLabel.snp.top).offset(-8)
- // }
- // }else{
- // typeImage.snp.remakeConstraints { make in
- // make.left.equalTo(musicContenView.snp.left)
- // make.height.width.equalTo(18)
- // make.bottom.equalTo(musicContenView.snp.top).offset(-cDefaultMargin)
- // }
- // }
- //
- // typeLab.snp.remakeConstraints { make in
- // make.left.equalTo(typeImage.snp.right).offset(5)
- // make.centerY.equalTo(typeImage)
- // make.right.equalTo(musicContenView)
- // }
- wxIV.snp.makeConstraints { make in
- make.right.equalTo(-12)
- make.bottom.equalTo(titleLabel.snp.top).offset(-9)
- make.width.height.equalTo(44)
- }
- friendIV.snp.makeConstraints { make in
- make.right.equalTo(wxIV.snp.left).offset(-8)
- make.width.height.bottom.equalTo(wxIV)
- }
- usageAmountL.snp.remakeConstraints { make in
- make.left.equalTo(12)
- make.height.equalTo(26)
- make.bottom.equalTo(titleLabel.snp.top).offset(-13)
- make.right.lessThanOrEqualTo(friendIV.snp.left).offset(-8)
- }
- }
- @objc func btnClick(sender: UIButton) {
- if sender.tag == 2201 {
- // 分享朋友圈
- // cShowHUB(superView: nil, msg: "分享朋友圈")
- sharedBtnClicHandle?(1)
- }else if sender.tag == 2202 {
- // 分享给微信好友
- // cShowHUB(superView: nil, msg: "分享微信好友")
- sharedBtnClicHandle?(2)
- }else if reCreateBtnClicHandle != nil {
- reCreateBtnClicHandle!(sender, videoData)
- }
- }
- required init?(coder _: NSCoder) {
- fatalError("init(coder:) has not been implemented")
- }
- }
|