0

I have table view and in every reusable cell there is a progress bar, now the question is how can i pause and play the progress and its animation if the the button is touched.

var  arr = [10 , 20 , 30 , 40]

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {

    let tablecell:TableViewCell = tableView.dequeueReusableCellWithIdentifier("cell") as! TableViewCell

    tablecell.tableImage.image = images[indexPath.row]
    tablecell.tabelLabel.text = nameUrl[indexPath.row]

    let count: Float = Float(arr[indexPath.row])

    if flag == false{
       tablecell.prog_bar.setProgress(count, animated: true)
    } else {
        tablecell.prog_bar.setProgress(0, animated: false)
        tableView.reloadData()
    }

    return tablecell
}
Bista
  • 7,869
  • 3
  • 27
  • 55
Hashem Al-Issa
  • 51
  • 1
  • 1
  • 5
  • 1
    Don't use `tableView.reloadData()` inside `cellForRow:`. – Bista Sep 21 '16 at 06:59
  • Use delegate to get the Cell `indexpath` where the Button is pressed. See this post for more info: http://stackoverflow.com/questions/39585638/get-indexpath-of-uitableviewcell-on-click-of-button-from-cell/39585749#39585749 – Bista Sep 21 '16 at 07:05
  • use slider Libraries from Github. – JAck Sep 21 '16 at 07:25
  • okay now i know how to add the action for the button in each cell, but how can i pause or resume the progress bar – Hashem Al-Issa Sep 21 '16 at 11:49

1 Answers1

0

Try these functions. These functions work perfectly.

func start() {
    self.progressview.progress = 1
    UIView.animate(withDuration: 5.0, delay: 0.0, options: .curveLinear, animations: {
        self.progressview.layoutIfNeeded()
    }, completion: nil)
}

func resume() {
    let layer = progressview.layer
    let pausedTime = layer.timeOffset
    layer.speed = 1.0
    layer.timeOffset = 0.0
    layer.beginTime = 0.0
    let timeSincePause = layer.convertTime(CACurrentMediaTime(), from: nil) - pausedTime
    layer.beginTime = timeSincePause

}

func pause() {
    let layer = progressview.layer
    let pausedTime = layer.convertTime(CACurrentMediaTime(), from: nil)
    layer.speed = 0.0
    layer.timeOffset = pausedTime

}
bad_coder
  • 11,289
  • 20
  • 44
  • 72