简体   繁体   中英

How can I create a countdown timer that stops at zero on iOS?

The app description would be something like this:

There are:

  • 3 buttons: start, reset and click here (the last one isn't enabled when the app starts)
  • 2 labels: timer and mainTimer

When you click on start button, the timer goes from 3 seconds to 0 seconds, when it reaches 0, it stops, the click here button gets enabled and the mainTimer gets active, it goes from 60 seconds to 0 seconds. Finally, when mainTimer reaches 0, the start button gets disabled again, the mainTimer stops, and an alert shows up saying: time's up!

When the alert disappears everything gets the same state as in the beginning by clicking the reset button, and you are able to repeat the process.

My main problems are stoping the timers on 0, becoming enabled and disabled the click here button and to make the reset button putting everything as they were in the beginning.

Thanks a lot!!

Please take a look at the NSTimer class reference. Your feature may be implemented with a property for the countdown, a property with the NSTimer and putting the pieces together :)

NSTimer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM