简体   繁体   English

如何在iOS上创建一个从零停止的倒数计时器?

[英]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) 3个按钮:启动,重置并单击此处(在应用启动时未启用最后一个按钮)
  • 2 labels: timer and mainTimer 2个标签:计时器和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. 当您单击开始按钮时,计时器从3秒变为0秒,到0时,计时器停止,单击此处按钮被启用,mainTimer变为活动状态,从60秒变为0秒。 Finally, when mainTimer reaches 0, the start button gets disabled again, the mainTimer stops, and an alert shows up saying: time's up! 最后,当mainTimer达到0时,开始按钮再次被禁用,mainTimer停止,并显示一条警告说:时间到了!

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. 我的主要问题是将计时器停止为0,启用和禁用“单击此处”按钮,并使“重置”按钮像开始时一样放置所有内容。

Thanks a lot!! 非常感谢!!

Please take a look at the NSTimer class reference. 请看一下NSTimer类参考。 Your feature may be implemented with a property for the countdown, a property with the NSTimer and putting the pieces together :) 您的功能可以通过倒计时的属性, NSTimer的属性并将各个部分放在一起来实现:)

NSTimer NSTimer

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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