IOSGCD定时器

2017-04-04  本文已影响945人  _CLAY_

GCD的定时器

//定义队列
    dispatch_queue_t queue = dispatch_get_global_queue(0, 0);
    //创建定时器
    self.timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
    
    dispatch_time_t start = DISPATCH_TIME_NOW;        //当前时间
    dispatch_time_t interval = 1.0 * NSEC_PER_SEC;    //间隔时间  --纳秒
    //设置定时器
    dispatch_source_set_timer(self.timer, start, interval, 0);
    //设置回调
    dispatch_source_set_event_handler(self.timer, ^{
        NSLog(@"-------%@",[NSThread currentThread]);
    });
    
    //启动定时器
    dispatch_resume(self.timer);
上一篇 下一篇

猜你喜欢

热点阅读