MVBannerCell.swift 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  1. //
  2. // GXBannerTestCell.swift
  3. // GXBannerSample
  4. //
  5. // Created by Gin on 2020/7/24.
  6. // Copyright © 2020 gin. All rights reserved.
  7. //
  8. import BFFramework
  9. import UIKit
  10. class MVBannerCell: UICollectionViewCell {
  11. // 做同款
  12. var reCreateBtnClicHandle: ((_ sender: UIButton, _ videoInfo: PQVideoListModel?) -> Void)?
  13. var sharedBtnClicHandle: ((_ type:Int) -> Void)?
  14. 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)
  15. // 封面
  16. lazy var converView: UIImageView = {
  17. let iv = UIImageView()
  18. iv.contentMode = .scaleAspectFill
  19. iv.clipsToBounds = true
  20. iv.addCorner(corner: 8)
  21. return iv
  22. }()
  23. lazy var progressView: UIProgressView = {
  24. let progressView = UIProgressView(progressViewStyle: .default)
  25. progressView.progressTintColor = .white
  26. return progressView
  27. }()
  28. // lazy var backShadowView: UIView = {
  29. // let backShowView = UIView()
  30. // backShowView.layer.masksToBounds = false
  31. // backShowView.layer.shadowColor = UIColor.black.cgColor
  32. // backShowView.layer.shadowOpacity = 0.3 // 设置阴影的透明度
  33. // backShowView.layer.shadowRadius = 4
  34. // backShowView.layer.shadowOffset = CGSize(width: 0, height: 4) // 设置阴影的偏移量
  35. // return backShowView
  36. // }()
  37. // 下面 marks view
  38. lazy var bottmMaskView: UIImageView = {
  39. let bottmMaskView = UIImageView(image: UIImage(named: "home_marks"))
  40. bottmMaskView.isUserInteractionEnabled = true
  41. bottmMaskView.addCorner(corner: 8)
  42. return bottmMaskView
  43. }()
  44. // 暂停view
  45. lazy var pauseView: UIImageView = {
  46. let pauseView = UIImageView(image: UIImage(named: "video_pause"))
  47. pauseView.isHidden = false
  48. return pauseView
  49. }()
  50. /// 音乐内容view
  51. lazy var musicContenView: UIView = {
  52. let musicContenView = UIView()
  53. return musicContenView
  54. }()
  55. // 音乐图片
  56. lazy var musicImageView: UIImageView = {
  57. let musicImageView = UIImageView(image: UIImage(named: "musicName_icon"))
  58. musicImageView.showLoadingAnimation(duration: 3)
  59. return musicImageView
  60. }()
  61. // 音乐背景
  62. lazy var musicBgView: UIImageView = {
  63. let musicBgView = UIImageView(image: UIImage(named: "musicName_bg"))
  64. return musicBgView
  65. }()
  66. /// 标题
  67. lazy var titleLabel: UILabel = {
  68. let titleLabel = UILabel()
  69. titleLabel.textAlignment = .left
  70. titleLabel.textColor = .white
  71. titleLabel.numberOfLines = 0
  72. titleLabel.lineBreakMode = .byCharWrapping
  73. titleLabel.setContentCompressionResistancePriority(.defaultLow, for: .vertical)
  74. titleLabel.font = UIFont.systemFont(ofSize: 16, weight: .bold)
  75. return titleLabel
  76. }()
  77. /// 音乐歌曲名称
  78. lazy var musicNameLab: LMJHorizontalScrollText = {
  79. let musicNameLab = LMJHorizontalScrollText(frame: CGRect(x: 12 + cDefaultMargin, y: 0, width: musicWidth, height: 32))
  80. musicNameLab.textColor = UIColor.white
  81. musicNameLab.textFont = UIFont.systemFont(ofSize: 15, weight: .semibold)
  82. musicNameLab.speed = 0.03
  83. musicNameLab.moveDirection = LMJTextScrollMoveLeft
  84. musicNameLab.moveMode = LMJTextScrollContinuous
  85. musicNameLab.stop()
  86. return musicNameLab
  87. }()
  88. lazy var reCreateBtn: UIButton = {
  89. let reCreateBtn = UIButton(type: .custom)
  90. reCreateBtn.setTitle(" 做同款", for: .normal)
  91. reCreateBtn.titleLabel?.font = UIFont.systemFont(ofSize: 15, weight: .semibold)
  92. reCreateBtn.setTitleColor(UIColor.white, for: .normal)
  93. reCreateBtn.addCorner(corner: 8)
  94. reCreateBtn.setImage(UIImage(named: "reCreate"), for: .normal)
  95. reCreateBtn.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
  96. reCreateBtn.backgroundColor = UIColor(red: 61.0 / 255.0, green: 193.0 / 255.0, blue: 193.0 / 255.0, alpha: 1)
  97. reCreateBtn.eventInterval = 0.5
  98. return reCreateBtn
  99. }()
  100. // 视频分类
  101. lazy var typeImage: UIImageView = {
  102. let typeImage = UIImageView(image: UIImage(named: "categary_icon"))
  103. return typeImage
  104. }()
  105. // 视频分类
  106. lazy var typeLab: UILabel = {
  107. let typeLab = UILabel()
  108. typeLab.font = UIFont.systemFont(ofSize: 14, weight: .semibold)
  109. typeLab.textColor = UIColor.white
  110. return typeLab
  111. }()
  112. lazy var usageAmountL:MVBannerUsageView = {
  113. let v = MVBannerUsageView()
  114. return v
  115. }()
  116. lazy var friendIV:UIButton = {
  117. // let iv = UIImageView(image: UIImage(named: "b_pyq"))
  118. let iv = UIButton(type: .custom)
  119. iv.setImage(UIImage(named: "b_pyq"), for: .normal)
  120. iv.tag = 2201
  121. iv.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
  122. // iv.layer.backgroundColor = UIColor.black.cgColor
  123. // iv.layer.cornerRadius = 22
  124. // iv.alpha = 0.3
  125. return iv
  126. }()
  127. lazy var wxIV:UIButton = {
  128. // let iv = UIImageView(image: UIImage(named: "b_wx"))
  129. let iv = UIButton(type: .custom)
  130. iv.setImage(UIImage(named: "b_wx"), for: .normal)
  131. iv.tag = 2202
  132. iv.addTarget(self, action: #selector(btnClick(sender:)), for: .touchUpInside)
  133. // iv.layer.backgroundColor = UIColor.black.cgColor
  134. // iv.layer.cornerRadius = 22
  135. // iv.alpha = 0.3
  136. return iv
  137. }()
  138. override func prepareForReuse() {
  139. musicNameLab.stop()
  140. }
  141. var videoData: PQVideoListModel? {
  142. didSet {
  143. addLayout()
  144. addData()
  145. }
  146. }
  147. override func layoutSubviews() {
  148. super.layoutSubviews()
  149. }
  150. override init(frame: CGRect) {
  151. super.init(frame: frame)
  152. // contentView.addSubview(backShadowView)
  153. contentView.addSubview(converView)
  154. contentView.addSubview(bottmMaskView)
  155. contentView.addSubview(pauseView)
  156. bottmMaskView.addSubview(progressView)
  157. // bottmMaskView.addSubview(typeImage)
  158. // bottmMaskView.addSubview(typeLab)
  159. bottmMaskView.addSubview(titleLabel)
  160. bottmMaskView.addSubview(usageAmountL)
  161. bottmMaskView.addSubview(friendIV)
  162. bottmMaskView.addSubview(wxIV)
  163. bottmMaskView.addSubview(reCreateBtn)
  164. bottmMaskView.addSubview(musicContenView)
  165. musicContenView.addSubview(musicBgView)
  166. musicContenView.addSubview(musicImageView)
  167. musicBgView.addSubview(musicNameLab)
  168. }
  169. func addData() {
  170. typeLab.text = "\(videoData?.categoryName ?? "")"
  171. BFLog(message: "videoDatavideoData \(String(describing: videoData?.title))")
  172. let textSize = sizeWithText(text: videoData?.title ?? "", font: UIFont.systemFont(ofSize: 16, weight: .bold), size: CGSize.init(width: self.frame.width - 24, height: CGFloat.greatestFiniteMagnitude))
  173. BFLog(message: "XXXXXXX videoData?.title is \(String(describing: videoData?.title)) height \(textSize.height) width is \(adapterWidth(width: 300))")
  174. BFLog(message: "videoData?.title is \(String(describing: videoData?.title)) height \(textSize.height)")
  175. titleLabel.text = videoData?.title ?? ""
  176. // if videoData?.categoryImage != nil {
  177. // typeImage.setNetImage(url: "\(videoData?.categoryImage ?? "")", placeholder: UIImage(named: "categary_icon")!)
  178. // } else {
  179. // typeImage.image = UIImage(named: "categary_icon")
  180. // }
  181. usageAmountL.amount = videoData?.reCreateVideoData?.reProduceCount ?? 0
  182. let coverImg = (videoData?.videoCoverSnapshotPath != nil && (videoData?.videoCoverSnapshotPath?.count ?? 0) > 0) ? videoData?.videoCoverSnapshotPath ?? "" : (videoData?.coverImg?["coverImgPath"] as? String ?? "")
  183. BFLog(message: "coverImg url is \(coverImg)")
  184. netImage(url: coverImg, mainView: converView)
  185. let nameWidth: CGFloat = sizeWithText(text: "\(videoData?.reCreateVideoData?.rhythmMusicName ?? "") ", font: UIFont.systemFont(ofSize: 15, weight: .semibold), size: CGSize(width: cScreenWidth, height: 32)).width
  186. musicNameLab.stop()
  187. if nameWidth > musicWidth {
  188. musicNameLab.move()
  189. musicNameLab.text = "\(videoData?.reCreateVideoData?.rhythmMusicName ?? "") "
  190. } else {
  191. musicNameLab.stop()
  192. musicNameLab.text = "\(videoData?.reCreateVideoData?.rhythmMusicName ?? "") "
  193. }
  194. }
  195. ///
  196. /// - Returns: <#description#>
  197. func addLayout() {
  198. // backShadowView.snp.remakeConstraints { make in
  199. // make.width.equalToSuperview()
  200. // make.height.equalToSuperview()
  201. // make.left.equalToSuperview()
  202. // make.top.equalToSuperview()
  203. // }
  204. converView.snp.remakeConstraints { make in
  205. make.left.bottom.top.right.equalToSuperview()
  206. }
  207. pauseView.snp.remakeConstraints { make in
  208. make.width.equalTo(82)
  209. make.height.equalTo(82)
  210. make.center.equalToSuperview()
  211. }
  212. bottmMaskView.snp.remakeConstraints { make in
  213. make.width.equalToSuperview()
  214. make.height.equalTo(150 + 100)
  215. make.left.equalToSuperview()
  216. make.bottom.equalToSuperview()
  217. }
  218. progressView.snp.remakeConstraints { make in
  219. make.height.equalTo(2)
  220. make.left.equalToSuperview().offset(3)
  221. make.right.equalToSuperview().offset(-3)
  222. make.bottom.equalToSuperview()
  223. }
  224. reCreateBtn.snp.remakeConstraints { make in
  225. make.width.equalTo(106)
  226. make.height.equalTo(46)
  227. make.right.equalToSuperview().offset(-cDefaultMargin)
  228. make.bottom.equalTo(progressView.snp.top).offset(-cDefaultMargin * 2)
  229. }
  230. musicContenView.snp.remakeConstraints { make in
  231. make.centerY.equalTo(reCreateBtn)
  232. make.height.equalTo(32)
  233. make.right.equalTo(reCreateBtn.snp.left).offset(-cDefaultMargin)
  234. make.left.equalToSuperview().offset(cDefaultMargin)
  235. }
  236. musicImageView.snp.makeConstraints { make in
  237. make.top.left.equalToSuperview()
  238. make.width.height.equalTo(musicContenView.snp.height)
  239. }
  240. musicBgView.snp.makeConstraints { make in
  241. make.left.equalTo(musicImageView.snp.centerX)
  242. make.right.top.height.equalToSuperview()
  243. }
  244. titleLabel.snp.remakeConstraints { make in
  245. make.width.equalToSuperview().offset(-24)
  246. // make.height.equalTo(textSize.height + 2)
  247. make.left.equalToSuperview().offset(12)
  248. make.bottom.equalTo(musicContenView.snp.top).offset(-cDefaultMargin - 2)
  249. }
  250. // if(videoData?.title?.count ?? 0 > 0){
  251. // typeImage.snp.remakeConstraints { make in
  252. // make.left.equalTo(musicContenView.snp.left)
  253. // make.height.width.equalTo(18)
  254. // make.bottom.equalTo(titleLabel.snp.top).offset(-8)
  255. // }
  256. // }else{
  257. // typeImage.snp.remakeConstraints { make in
  258. // make.left.equalTo(musicContenView.snp.left)
  259. // make.height.width.equalTo(18)
  260. // make.bottom.equalTo(musicContenView.snp.top).offset(-cDefaultMargin)
  261. // }
  262. // }
  263. //
  264. // typeLab.snp.remakeConstraints { make in
  265. // make.left.equalTo(typeImage.snp.right).offset(5)
  266. // make.centerY.equalTo(typeImage)
  267. // make.right.equalTo(musicContenView)
  268. // }
  269. wxIV.snp.makeConstraints { make in
  270. make.right.equalTo(-12)
  271. make.bottom.equalTo(titleLabel.snp.top).offset(-9)
  272. make.width.height.equalTo(44)
  273. }
  274. friendIV.snp.makeConstraints { make in
  275. make.right.equalTo(wxIV.snp.left).offset(-8)
  276. make.width.height.bottom.equalTo(wxIV)
  277. }
  278. usageAmountL.snp.remakeConstraints { make in
  279. make.left.equalTo(12)
  280. make.height.equalTo(26)
  281. make.bottom.equalTo(titleLabel.snp.top).offset(-13)
  282. make.right.lessThanOrEqualTo(friendIV.snp.left).offset(-8)
  283. }
  284. }
  285. @objc func btnClick(sender: UIButton) {
  286. if sender.tag == 2201 {
  287. // 分享朋友圈
  288. // cShowHUB(superView: nil, msg: "分享朋友圈")
  289. sharedBtnClicHandle?(1)
  290. }else if sender.tag == 2202 {
  291. // 分享给微信好友
  292. // cShowHUB(superView: nil, msg: "分享微信好友")
  293. sharedBtnClicHandle?(2)
  294. }else if reCreateBtnClicHandle != nil {
  295. reCreateBtnClicHandle!(sender, videoData)
  296. }
  297. }
  298. required init?(coder _: NSCoder) {
  299. fatalError("init(coder:) has not been implemented")
  300. }
  301. }