码迷,mamicode.com
首页 > 其他好文 > 详细

使用GCD验证码倒计时

时间:2016-03-22 12:28:01      阅读:173      评论:0      收藏:0      [点我收藏+]

标签:

 __block int timeout = 60;
    dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0);
    
    dispatch_source_t source_t = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    
    dispatch_source_set_timer(source_t, dispatch_walltime(NULL, 0), 1*NSEC_PER_SEC, 0);
    
    dispatch_source_set_event_handler(source_t, ^{
        
        if (timeout<=0) {
            
            dispatch_source_cancel(source_t);
            dispatch_async(dispatch_get_main_queue(), ^{
                
                NSLog(@"重新开始倒计时");
            });
            
            
        }
        else
        {
            dispatch_async(dispatch_get_main_queue(), ^{
                
                NSLog(@"开始倒计时剩余%.2ds",timeout%60);
            });
        
            timeout --;
            
            
        }
        
        
        
    });
    dispatch_resume(source_t);
    
    
    
    
    
    

  

使用GCD验证码倒计时

标签:

原文地址:http://www.cnblogs.com/thbbsky/p/5305541.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!