- 语音消息 显示
|
After Width: | Height: | Size: 251 B |
|
After Width: | Height: | Size: 366 B |
|
After Width: | Height: | Size: 518 B |
|
After Width: | Height: | Size: 51 KiB |
|
After Width: | Height: | Size: 25 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 58 KiB |
|
After Width: | Height: | Size: 8.1 KiB |
|
After Width: | Height: | Size: 2.0 MiB |
|
|
@ -876,9 +876,14 @@ final class VoiceSendMsgCell: UITableViewCell {
|
|||
return v
|
||||
}()
|
||||
|
||||
private let playIcon: UIImageView = {
|
||||
let iv = UIImageView(image: UIImage(named: "IM/video_send"))
|
||||
return iv
|
||||
private let playAnimation: LottieAnimationView = {
|
||||
let v = LottieAnimationView()
|
||||
if let path = Bundle.main.path(forResource: "message_voice_play", ofType: "json") {
|
||||
v.animation = LottieAnimation.filepath(path)
|
||||
}
|
||||
v.loopMode = .loop
|
||||
v.contentMode = .scaleAspectFit
|
||||
return v
|
||||
}()
|
||||
|
||||
private let durationLabel: UILabel = {
|
||||
|
|
@ -894,10 +899,13 @@ final class VoiceSendMsgCell: UITableViewCell {
|
|||
backgroundColor = .clear
|
||||
contentView.addSubview(timeLabel)
|
||||
contentView.addSubview(bubbleView)
|
||||
bubbleView.addSubview(playIcon)
|
||||
bubbleView.addSubview(playAnimation)
|
||||
bubbleView.addSubview(durationLabel)
|
||||
contentView.addSubview(avatarView)
|
||||
|
||||
|
||||
let tap = UITapGestureRecognizer(target: self, action: #selector(togglePlay))
|
||||
bubbleView.addGestureRecognizer(tap)
|
||||
|
||||
timeLabel.layoutChain.top().centerX()
|
||||
avatarView.layoutChain
|
||||
.topToBottomOfView(timeLabel, offset: 14)
|
||||
|
|
@ -908,13 +916,13 @@ final class VoiceSendMsgCell: UITableViewCell {
|
|||
.rightToView(avatarView, offset: -13)
|
||||
.width(105).height(39).bottom(10)
|
||||
|
||||
playIcon.layoutChain
|
||||
playAnimation.layoutChain
|
||||
.right(36)
|
||||
.centerY()
|
||||
.width(11).height(15)
|
||||
.width(20).height(20)
|
||||
|
||||
durationLabel.layoutChain
|
||||
.leftToRightOfView(playIcon, offset: 8)
|
||||
.leftToRightOfView(playAnimation, offset: 4)
|
||||
.centerY()
|
||||
}
|
||||
|
||||
|
|
@ -930,6 +938,19 @@ final class VoiceSendMsgCell: UITableViewCell {
|
|||
durationLabel.text = dur > 0 ? "\(dur)''" : ""
|
||||
}
|
||||
|
||||
@objc private func togglePlay() {
|
||||
if playAnimation.isAnimationPlaying {
|
||||
playAnimation.stop()
|
||||
} else {
|
||||
playAnimation.play()
|
||||
}
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
playAnimation.stop()
|
||||
}
|
||||
|
||||
private func formatTime(_ t: TimeInterval) -> String {
|
||||
let date = Date(timeIntervalSince1970: t)
|
||||
let now = Date()
|
||||
|
|
@ -941,7 +962,7 @@ final class VoiceSendMsgCell: UITableViewCell {
|
|||
else { f.dateFormat = "yyyy-M-d HH:mm" }
|
||||
return f.string(from: date)
|
||||
}
|
||||
|
||||
|
||||
override func layoutSubviews() {
|
||||
super.layoutSubviews()
|
||||
bubbleView.setNeedsLayout()
|
||||
|
|
@ -987,9 +1008,14 @@ final class VoiceReceivedMsgCell: UITableViewCell {
|
|||
return v
|
||||
}()
|
||||
|
||||
private let playIcon: UIImageView = {
|
||||
let iv = UIImageView(image: UIImage(named: "IM/video_received"))
|
||||
return iv
|
||||
private let playAnimation: LottieAnimationView = {
|
||||
let v = LottieAnimationView()
|
||||
if let path = Bundle.main.path(forResource: "message_voice_play", ofType: "json") {
|
||||
v.animation = LottieAnimation.filepath(path)
|
||||
}
|
||||
v.loopMode = .loop
|
||||
v.contentMode = .scaleAspectFit
|
||||
return v
|
||||
}()
|
||||
|
||||
private let durationLabel: UILabel = {
|
||||
|
|
@ -1005,10 +1031,12 @@ final class VoiceReceivedMsgCell: UITableViewCell {
|
|||
backgroundColor = .clear
|
||||
contentView.addSubview(timeLabel)
|
||||
contentView.addSubview(bubbleView)
|
||||
bubbleView.addSubview(playIcon)
|
||||
bubbleView.addSubview(playAnimation)
|
||||
bubbleView.addSubview(durationLabel)
|
||||
contentView.addSubview(avatarView)
|
||||
contentView.addSubview(nameLabel)
|
||||
let tap = UITapGestureRecognizer(target: self, action: #selector(togglePlay))
|
||||
bubbleView.addGestureRecognizer(tap)
|
||||
|
||||
timeLabel.layoutChain.top().centerX()
|
||||
|
||||
|
|
@ -1029,13 +1057,13 @@ final class VoiceReceivedMsgCell: UITableViewCell {
|
|||
.leftToRightOfView(avatarView, offset: 5)
|
||||
.bottomToView(avatarView)
|
||||
|
||||
playIcon.layoutChain
|
||||
playAnimation.layoutChain
|
||||
.left(36)
|
||||
.centerY()
|
||||
.width(11).height(15)
|
||||
.width(20).height(20)
|
||||
|
||||
durationLabel.layoutChain
|
||||
.leftToRightOfView(playIcon, offset: 8)
|
||||
.leftToRightOfView(playAnimation, offset: 4)
|
||||
.centerY()
|
||||
}
|
||||
|
||||
|
|
@ -1052,6 +1080,19 @@ final class VoiceReceivedMsgCell: UITableViewCell {
|
|||
durationLabel.text = dur > 0 ? "\(dur)''" : ""
|
||||
}
|
||||
|
||||
@objc func togglePlay() {
|
||||
if playAnimation.isAnimationPlaying {
|
||||
playAnimation.stop()
|
||||
} else {
|
||||
playAnimation.play()
|
||||
}
|
||||
}
|
||||
|
||||
override func prepareForReuse() {
|
||||
super.prepareForReuse()
|
||||
playAnimation.stop()
|
||||
}
|
||||
|
||||
private func formatTime(_ t: TimeInterval) -> String {
|
||||
let date = Date(timeIntervalSince1970: t)
|
||||
let now = Date()
|
||||
|
|
|
|||