读书人

【ios范例小计】NSTimer 定时器的使用

发布时间: 2013-10-08 16:38:32 作者: rapoo

【ios实例小计】NSTimer 定时器的使用


预备知识:
1.NSTimer其实是将一个监听加入的系统的RunLoop中去,当系统runloop到如何timer条件的循环时,会调用timer一次,当timer执行完,也就是回调函数执行之后,timer会再一次的将自己加入到runloop中去继续监听。(此处不深入讨论,有兴趣的可以去苹果官方文档RunLoop看看)
2.
NSTimer是Cocoa中比较常用的定时器类
基本操作如下:
handleTimer方法可以自行定义。在需要的地方创建timer即可,handleTimer就可以每0.5秒执行一次。


效果图:

【ios范例小计】NSTimer 定时器的使用

这样就完成倒计时了,里面加上了一些用到的知识,另外第一次写排版不好,大家勿喷。

参考:

http://blog.sina.com.cn/s/blog_5fae23350100djg2.html
http://www.cocoachina.com/b/?cat=42
http://blog.csdn.net/namehzf/article/details/7294766

http://blog.csdn.net/wishfly/article/details/7370277

http://www.cnblogs.com/wujian1360/archive/2011/09/05/2168007.html

http://blog.csdn.net/ch_soft/article/details/7387694

读书人网 >操作系统

热点推荐