【发布时间】:2018-08-26 23:09:17
【问题描述】:
我正在寻找可以以编程方式帮助我在 UITableViewCell 上添加 UIProgressView 的帖子/链接/指南。目前,我按住的每个单元格都会播放从 Firebase 流式传输的音频,当我松开时,音频会停止。我想添加一个 ProgressView,它首先以清晰的色调覆盖单元格的整个框架,但变成浅蓝色或其他颜色来描绘它从左到右的进度。音频的持续时间将决定进度视图的速度。我搜遍了SO,只能找到几年前用Obj C写的similar posts;寻找用最新的 Swift 语言编写的东西。下面是我在谷歌上搜索的一个随机 gif,它显示了我正在寻找的内容。非常感谢任何帮助。
更新 1:
我设法获得了持续时间并申请了进度。 UIProgressView 相应地记录进度从左到右的持续时间。现在唯一的问题是,当我按下 any 单元格播放其各自的音频时,first 单元格的进度条会播放。下面是我正在使用的代码。
@objc func updateProgress(){
let duration = Float((player.currentItem?.duration.seconds)!)
let currentTime = Float((player.currentItem?.currentTime().seconds)!)
let progressTotal = currentTime/duration
let indexPath = IndexPath(row: self.tag, section: 0)
if progressTotal > 0 {
if let cell = tableView.cellForRow(at: indexPath) as? PostTableViewCell {
if currentTime != duration || currentTime/duration != 1 {
cell.progressBar.progress = progressTotal
cell.progressBar.progressTintColor = UIColor.blue
} else {
timer?.invalidate()
if timer != nil {
timer?.invalidate()
timer = nil
print("Timer Stopped")
}
}
}
}
}
【问题讨论】:
标签: ios uitableview swift4 uiprogressview