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

延迟执行的几种方法

时间:2019-02-21 00:27:39      阅读:198      评论:0      收藏:0      [点我收藏+]

标签:delay   convert   elf   方法   ted   inf   nstimer   font   isp   

第一种:

  [self performSelector:@selector(run) withObject:nil afterDelay:2.0];

 

第二种:

  [NSTimer scheduledTimerWithTimeInterval:2.0 target:self selector:@selector(run) userInfo:nil repeats:NO];

第三种:最好

  dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

 

        NSLog(@"--------delay-------");

    });

 

GCD中的时间单位是纳秒。

延迟执行的原理是:先等2秒,再把任务提交到队列中执行。

延迟执行的几种方法

标签:delay   convert   elf   方法   ted   inf   nstimer   font   isp   

原文地址:https://www.cnblogs.com/dashengios/p/10409862.html

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