|
@@ -1,4 +1,7 @@
|
|
|
//
|
|
|
+import BFCommonKit
|
|
|
+import BFMediaKit
|
|
|
+import BFUIKit
|
|
|
// PQVoiceCell.swift
|
|
|
// PQSpeed
|
|
|
//
|
|
@@ -6,81 +9,56 @@
|
|
|
// Copyright © 2020 BytesFlow. All rights reserved.
|
|
|
//
|
|
|
import Foundation
|
|
|
-import BFMediaKit
|
|
|
-import BFUIKit
|
|
|
-import BFCommonKit
|
|
|
+import UIKit
|
|
|
|
|
|
class PQVoiceCell: UICollectionViewCell {
|
|
|
- lazy var background: UIView = {
|
|
|
- let background = UIView()
|
|
|
- background.backgroundColor = UIColor.clear
|
|
|
- return background
|
|
|
- }()
|
|
|
-
|
|
|
- //头像
|
|
|
+
|
|
|
+ // 头像
|
|
|
lazy var coverView: UIImageView = {
|
|
|
let coverView = UIImageView()
|
|
|
coverView.backgroundColor = UIColor.clear
|
|
|
- coverView.addCorner(corner: 30)
|
|
|
+ coverView.addCorner(corner: 25)
|
|
|
+
|
|
|
return coverView
|
|
|
}()
|
|
|
|
|
|
-
|
|
|
lazy var nameLab: UILabel = {
|
|
|
let nameLab = UILabel()
|
|
|
- nameLab.textColor = UIColor.hexColor(hexadecimal: "#E4E4E4")
|
|
|
- nameLab.addCorner(corner: 3)
|
|
|
- nameLab.font = UIFont.systemFont(ofSize: 11)
|
|
|
+ nameLab.font = UIFont.systemFont(ofSize: 15)
|
|
|
nameLab.textAlignment = .center
|
|
|
return nameLab
|
|
|
}()
|
|
|
-
|
|
|
- lazy var markView: UIView = {
|
|
|
- let markView = UIView(frame: self.frame)
|
|
|
- markView.backgroundColor = UIColor.black
|
|
|
- markView.alpha = 0.7
|
|
|
+
|
|
|
+ lazy var markView: UIImageView = {
|
|
|
+ let markView = UIImageView()
|
|
|
markView.isHidden = true
|
|
|
return markView
|
|
|
}()
|
|
|
|
|
|
- // 语音加载动画
|
|
|
+ // 语音加载中动画
|
|
|
lazy var audioLoding: UIImageView = {
|
|
|
let audioLoding = UIImageView(frame: self.frame)
|
|
|
-
|
|
|
- audioLoding.image = UIImage(named: "audioLoding")
|
|
|
+ audioLoding.image = imageInRecordScreenKit(by: "audioLoding")?.withRenderingMode(.alwaysTemplate)
|
|
|
audioLoding.isHidden = true
|
|
|
-
|
|
|
+ audioLoding.tintColor = .white
|
|
|
return audioLoding
|
|
|
}()
|
|
|
|
|
|
- // 语音播放动画
|
|
|
+ // 语音播放动画和暂停播放
|
|
|
lazy var audioPlaying: UIImageView = {
|
|
|
- let audioPlaying = UIImageView()
|
|
|
-
|
|
|
- var images = [UIImage]()
|
|
|
-// for i in 0...44 {
|
|
|
-// images.append(UIImage(named: "\(i).png")!)
|
|
|
-// }
|
|
|
-
|
|
|
- audioPlaying.animationImages = images
|
|
|
- audioPlaying.animationDuration = 2
|
|
|
- audioPlaying.animationRepeatCount = 0
|
|
|
-
|
|
|
- audioPlaying.isHidden = true
|
|
|
-
|
|
|
- return audioPlaying
|
|
|
+ let playImageView = UIImageView()
|
|
|
+ playImageView.image = imageInRecordScreenKit(by: "stuckPoint_music_pause")
|
|
|
+ playImageView.contentMode = .scaleAspectFit
|
|
|
+ return playImageView
|
|
|
}()
|
|
|
|
|
|
override init(frame: CGRect) {
|
|
|
super.init(frame: frame)
|
|
|
- backgroundColor = UIColor.clear
|
|
|
- contentView.addSubview(background)
|
|
|
- background.addSubview(coverView)
|
|
|
- background.addSubview(markView)
|
|
|
- background.addSubview(nameLab)
|
|
|
- background.addSubview(audioLoding)
|
|
|
- background.addSubview(audioPlaying)
|
|
|
-
|
|
|
+ contentView.addSubview(coverView)
|
|
|
+ contentView.addSubview(markView)
|
|
|
+ contentView.addSubview(nameLab)
|
|
|
+ contentView.addSubview(audioLoding)
|
|
|
+ contentView.addSubview(audioPlaying)
|
|
|
}
|
|
|
|
|
|
required init?(coder _: NSCoder) {
|
|
@@ -110,93 +88,83 @@ class PQVoiceCell: UICollectionViewCell {
|
|
|
|
|
|
func addData() {
|
|
|
nameLab.text = voice?.name
|
|
|
-// netImage(url: voice!.avatarUrl, mainView: coverView)
|
|
|
|
|
|
coverView.setNetImage(url: "\(voice?.avatarUrl ?? "")")
|
|
|
- BFLog(message: "voice!.voiceStatue is \(voice?.name) : \(voice!.voiceStatue)")
|
|
|
+ BFLog(message: "voice!.voiceStatue is \(voice?.name ?? "") : \(voice!.voiceStatue)")
|
|
|
+
|
|
|
+ // 0控制蒙层
|
|
|
if voice!.voiceStatue == .isNormal {
|
|
|
markView.isHidden = true
|
|
|
+ } else {
|
|
|
+ markView.isHidden = false
|
|
|
+ if voice!.voiceStatue == .isSelected {
|
|
|
+ markView.image = imageInRecordScreenKit(by: "markSeleced")
|
|
|
+ } else {
|
|
|
+ markView.image = imageInRecordScreenKit(by: "markPlaying")
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- background.layer.borderWidth = 0
|
|
|
- nameLab.textColor = UIColor.white
|
|
|
+ // 1控制文字
|
|
|
+ nameLab.textColor = voice!.voiceStatue == .isNormal ? UIColor.white : UIColor.hexColor(hexadecimal: "#389AFF")
|
|
|
|
|
|
- audioPlaying.isHidden = true
|
|
|
- audioPlaying.stopAnimating()
|
|
|
- audioLoding.isHidden = true
|
|
|
- audioLoding.stopAnimating()
|
|
|
+ // 2控制播放状态
|
|
|
+ if voice!.voiceStatue == .isPlaying {
|
|
|
+ BFLog(message: "设置到播放状态!")
|
|
|
+ audioPlaying.isHidden = false
|
|
|
+ audioPlaying.kf.setImage(with: URL(fileURLWithPath: currentBundle()!.path(forResource: "stuckPoint_music_playing", ofType: ".gif")!))
|
|
|
+ } else if voice!.voiceStatue == .isPause {
|
|
|
+ audioPlaying.isHidden = false
|
|
|
+ audioPlaying.image = imageInRecordScreenKit(by: "stuckPoint_music_pause")
|
|
|
|
|
|
} else {
|
|
|
- markView.isHidden = false
|
|
|
- background.layer.borderWidth = 2 / 812 * cScreenHeigth
|
|
|
- background.layer.borderColor = UIColor.hexColor(hexadecimal: "#EE0051").cgColor
|
|
|
-
|
|
|
- nameLab.textColor = UIColor.hexColor(hexadecimal: "#EE0051")
|
|
|
-
|
|
|
- if voice!.voiceStatue == .isPlaying {
|
|
|
- BFLog(message: "设置到播放状态!")
|
|
|
- audioPlaying.isHidden = false
|
|
|
- audioLoding.stopAnimating()
|
|
|
- audioPlaying.stopAnimating()
|
|
|
- audioPlaying.startAnimating()
|
|
|
-
|
|
|
- audioLoding.isHidden = true
|
|
|
- } else if voice!.voiceStatue == .isLoading {
|
|
|
- audioLoding.layer.removeAllAnimations()
|
|
|
- audioPlaying.stopAnimating()
|
|
|
- audioLoding.isHidden = false
|
|
|
- audioPlaying.isHidden = true
|
|
|
- // 1.创建动画
|
|
|
- let rotationAnim = CABasicAnimation(keyPath: "transform.rotation.z")
|
|
|
- // 2.设置动画的属性
|
|
|
- rotationAnim.fromValue = 0
|
|
|
- rotationAnim.toValue = Double.pi * 2
|
|
|
- rotationAnim.repeatCount = MAXFLOAT
|
|
|
- rotationAnim.duration = 1
|
|
|
- // 这个属性很重要 如果不设置当页面运行到后台再次进入该页面的时候 动画会停止
|
|
|
- rotationAnim.isRemovedOnCompletion = false
|
|
|
- // 3.将动画添加到layer中
|
|
|
- audioLoding.layer.add(rotationAnim, forKey: nil)
|
|
|
- } else if voice!.voiceStatue == .isSelected {
|
|
|
- audioLoding.isHidden = true
|
|
|
- audioPlaying.isHidden = true
|
|
|
-
|
|
|
- audioPlaying.stopAnimating()
|
|
|
- audioLoding.stopAnimating()
|
|
|
- }
|
|
|
+ audioPlaying.isHidden = true
|
|
|
}
|
|
|
|
|
|
+ // 3控制加载中状态
|
|
|
+ if voice!.voiceStatue == .isLoading {
|
|
|
+ audioLoding.layer.removeAllAnimations()
|
|
|
+ audioLoding.isHidden = false
|
|
|
+ // 1.创建动画
|
|
|
+ let rotationAnim = CABasicAnimation(keyPath: "transform.rotation.z")
|
|
|
+ // 2.设置动画的属性
|
|
|
+ rotationAnim.fromValue = 0
|
|
|
+ rotationAnim.toValue = Double.pi * 2
|
|
|
+ rotationAnim.repeatCount = MAXFLOAT
|
|
|
+ rotationAnim.duration = 1
|
|
|
+ // 这个属性很重要 如果不设置当页面运行到后台再次进入该页面的时候 动画会停止
|
|
|
+ rotationAnim.isRemovedOnCompletion = false
|
|
|
+ // 3.将动画添加到layer中
|
|
|
+ audioLoding.layer.add(rotationAnim, forKey: nil)
|
|
|
+ } else {
|
|
|
+ audioLoding.layer.removeAllAnimations()
|
|
|
+ audioLoding.isHidden = true
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
func addLayout() {
|
|
|
-
|
|
|
- background.snp.makeConstraints { make in
|
|
|
- make.top.equalToSuperview()
|
|
|
- make.right.equalToSuperview()
|
|
|
- make.left.bottom.equalToSuperview()
|
|
|
- }
|
|
|
coverView.snp.makeConstraints { make in
|
|
|
- make.top.left.equalToSuperview()
|
|
|
- make.width.height.equalTo(background.snp.width)
|
|
|
+ make.top.equalToSuperview()
|
|
|
+ make.centerX.equalToSuperview()
|
|
|
+ make.width.height.equalTo(50)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
nameLab.snp.makeConstraints { make in
|
|
|
- make.top.equalTo(coverView.snp.bottom)
|
|
|
- make.bottom.centerX.equalToSuperview()
|
|
|
+ make.top.equalTo(coverView.snp.bottom).offset(7)
|
|
|
+ make.centerX.equalToSuperview()
|
|
|
+ make.bottom.equalToSuperview()
|
|
|
}
|
|
|
|
|
|
audioLoding.snp.makeConstraints { make in
|
|
|
make.center.equalTo(coverView.snp.center)
|
|
|
- make.height.width.equalTo(adapterHeight(height: cDefaultMargin * 3))
|
|
|
+ make.height.width.equalTo(18)
|
|
|
}
|
|
|
audioPlaying.snp.makeConstraints { make in
|
|
|
make.center.equalTo(coverView.snp.center)
|
|
|
- make.height.width.equalTo(adapterHeight(height: cDefaultMargin * 3))
|
|
|
+ make.height.width.equalTo(18)
|
|
|
}
|
|
|
markView.snp.makeConstraints { make in
|
|
|
- make.size.equalToSuperview()
|
|
|
+ make.size.equalTo(coverView)
|
|
|
+ make.centerX.equalTo(coverView)
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|