Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Continue countdown timer after being paused #7

Closed
nurlan-dzhavadov opened this issue Mar 26, 2021 · 3 comments
Closed

Continue countdown timer after being paused #7

nurlan-dzhavadov opened this issue Mar 26, 2021 · 3 comments

Comments

@nurlan-dzhavadov
Copy link

nurlan-dzhavadov commented Mar 26, 2021

Hello!

Thanks for this library, it has helped me a lot! I have one problem. I have implemented a timer in my app and use 3 button to control this timer: Start, Stop and Pause. The problem is that when user presses Pause the timer pauses, but when the user presses Start, it doesn't continue running from where it was paused, because I don't know how to do that. Here is my code:

`import UIKit
import MagicTimer

class TimerVC: UIViewController {

var currentTaskDefaultTime = 10.0


@IBOutlet weak var timer: MagicTimerView!

@IBOutlet weak var startButton: UIButton!

@IBOutlet weak var pauseButton: UIButton!

@IBOutlet weak var stopButton: UIButton!

@IBAction func pressedStartButton(_ sender: Any) {
    startButton.isHidden = true
    pauseButton.isHidden = false
    stopButton.isHidden = false
    
    timer.mode = .countDown(fromSeconds: currentTaskDefaultTime)
    timer.isActiveInBackground = true
    timer.startCounting()
    
    
    
}

@IBAction func pressedPauseButton(_ sender: Any) {
    timer.stopCounting()
    startButton.isHidden = false
    completeTaskButton.isHidden = true
}

@IBAction func pressedStopButton(_ sender: Any) {
    timer.resetToDefault()
    startButton.isHidden = false
    pauseButton.isHidden = true
    stopButton.isHidden = true
}



override func viewDidLoad() {
    super.viewDidLoad()
    
    timer.font = UIFont(name: "Comfortaa-Semibold", size: 50)
    
    //hides by default the buttons
    pauseButton.isHidden = true
    stopButton.isHidden = true
}

}
`

Please help me

Sincerely yours
Nurlan

@nurlan-dzhavadov
Copy link
Author

nurlan-dzhavadov commented Mar 26, 2021

I have tried to use elapsedTime in the function pressedStartButton to continue running the timer from (default time - elapsedTime) if elapsedTime>0, but I get this error:

'elapsedTime' is inaccessible due to 'internal' protection level

@sadeghgoo
Copy link
Member

Hi;
Your sample code is the same as the MagicTimer example please review the example. If the issue exists in the example re-open another issue.

@sadeghgoo
Copy link
Member

If you want to resume timer just call startCounting() method.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants