简体   繁体   English

倒数计时器视图控制器

[英]CountDown timer View controller

I'm working on a project where i have to create a countdown timer, just like timers used in some recipe apps. 我正在一个必须创建倒数计时器的项目中,就像某些食谱应用中使用的计时器一样。 My question is that how do i go about creating a timer class/viewcontroller that can be called (by tapping on custom statusbar) from any view within the app... i believe it would not be a normal view controller since this one has to continue updating timer label on the UI even if it's hidden and not on the display. 我的问题是,我该如何创建可从应用程序内任何视图调用(通过点击自定义状态栏)的计时器类/视图控制器...我相信它将不是普通的视图控制器,因为该控制器必须继续更新UI上的计时器标签,即使它已隐藏而不在显示屏上也是如此。 is it a good idea to create timer's view in appdelegate and keep it hidden till it gets called?? 在appdelegate中创建计时器视图并将其隐藏直到被调用是个好主意吗?

seeking professional's advice! 寻求专业意见!

Distinguish model, view, and controller. 区分模型,视图和控制器。 The time may continue to count, and that might indeed be because the app delegate has an NSTimer. 时间可能会继续计时 ,这确实可能是因为应用程序委托具有NSTimer。 But the timer view does not need to keep updating, or even exist, if it is hidden. 但是,如果计时器视图是隐藏的,则不需要继续更新甚至存在。 If you need to show it, you create it, and it consults the NSTimer, the app delegate, or whatever the central model keeper is, and updates itself. 如果需要显示它,请创建它,然后它会咨询NSTimer,应用程序委托或任何中央模型维护者,并进行自我更新。

So it may look as though the same view is appearing in different places in your interface but actually it is a new view instance each time. 因此, 看起来相同的视图似乎出现在界面的不同位置,但实际上每次都是新的视图实例。 This could be because it is a new view controller instance. 这可能是因为它是一个新的视图控制器实例。 The view controller instance and its view comes into existence when needed and goes back out of existence when not needed, but the timer just keeps on keeping on. 视图控制器实例及其视图在需要时就存在,而在不需要时又不存在,但是计时器一直保持下去。

它可能是一个“普通”的uiviewcontroller,您只需要添加一个NSTimer,经过一定时间后它将调用一些选择器(您可以在其中更新自定义栏)。

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

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