倒计时实现的两种方法

timeFireMethod函数,timeFireMethod进行倒计时的一些操作,完成时把timer给invalidate掉就ok了,代码如下:

 secondsCountDown = ;//60秒倒计时
  countDownTimer = [NSTimer scheduledTimerWithTimeInterval: <span style=" target="_blank" href="http://cpro.baidu.com/cpro/ui/uijs.php?app_id=0&c=news&cf=1001&ch=0&di=128&fv=0&is_app=0&jk=d75e9253f4ee3769&k=target&k0=target&kdi0=0&luki=2&n=10&p=baidu&q=70084051_cpr&rb=0&rs=1&seller_id=1&sid=6937eef453925ed7&ssp2=1&stid=0&t=tpclicked3_hc&tu=u1996075&u=http%3A%2F%2Fubluesky%2Ecom%2Farchives%2F344&urlid=0" id="1_nwl"><span style="color:#0000ff;font-size:14px;width:auto;height:auto;float:none;">target</span></a></span>:self selector:@selector(timeFireMethod) userInfo:nil repeats:YES];
 -(void)timeFireMethod{
     secondsCountDown--;
     ){
       [countDownTimer invalidate];
     }
 }
 
 

方法2:使用GCD来实现

代码如下:

 __block ; //倒计时时间
 dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, );
 dispatch_source_t _timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, , ,queue);
 dispatch_source_set_timer(_timer,dispatch_walltime(NULL, ),); //每秒执行
 dispatch_source_set_event_handler(_timer, ^{
     ){ //倒计时结束,关闭
         dispatch_source_cancel(_timer);
         dispatch_release(_timer);
         dispatch_async(dispatch_get_main_queue(), ^{
     //设置界面的按钮显示 根据自己需求设置
             。。。。。。。。
         });
     }else{
         ;
         ;
         NSString *strTime = [NSString stringWithFormat:@"%d分%.2d秒后重新获取验证码",minutes, seconds];
         dispatch_async(dispatch_get_main_queue(), ^{
             //设置界面的按钮显示 根据自己需求设置
     。。。。。。。。
         });
         timeout--;

     }
 });
 dispatch_resume(_timer);

最新文章

  1. HashMap和HashSet
  2. C++类的底层机理
  3. unity, LoadLevelAdditive到帧末才完成
  4. C#调用MySql
  5. 干掉cmd:windows下使用linux命令行
  6. 【JAVA】浅谈java内部类
  7. HttpClient使用cookie
  8. zepto源码研究 - zepto.js (zepto.init)
  9. 剑指offer-面试题2.实例Singleton模式
  10. 类中成员函数与数据成员private/pubic/protected
  11. Python sphinx-build在Windows系统中生成Html文档
  12. 【Java并发系列03】ThreadLocal详解
  13. 新手之VM下安装centos版本Linux系统完整版!
  14. PIL绘图
  15. javascript基础 之 代码规范
  16. linux开通端口允许其他机器访问
  17. JAVA编程思想的理解
  18. 消除element.style { }
  19. UnicodeMath数学公式编码_翻译(Unicode Nearly Plain - Text Encoding of Mathematics Version 3)
  20. kafka性能测试1.0.0

热门文章

  1. [Everyday Mathematics]20150209
  2. 基于Hbase数据的Mapreduce程序环境开发
  3. vim对erlang语法支持
  4. 分布式文件系统-HDFS
  5. 对unsigned int和int进行移位操作的区别
  6. Mongoose:Schema之路
  7. 在Heroku上部署MEAN
  8. VB调用自持字体
  9. 第二百四十八天 how can I 坚持
  10. 【转】浅析C语言的非局部跳转:setjmp和longjmp