iOS-GCD 延迟处理dispatch_after

dispatch_after是在指定时间后,将执行加入到队列中。

dispatch_after的用法如下:

dispatch_time_t time=dispatch_time(DISPATCH_TIME_NOW, 2ull *NSEC_PER_SEC); //设置时间2秒
dispatch_after(time, dispatch_get_main_queue(), ^{
        //2秒后执行操作
        //添加操作
 });


也可以用以下写法:

dispatch_after_f(dispatch_time(DISPATCH_TIME_NOW, 2ull *NSEC_PER_SEC), dispatch_get_main_queue(), NULL, function);//function为自己定义的执行方法

dispatch_afer搭配hud使用起来效果更加

[SVProgressHUD showWithStatus:@"正在清理..."];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2ull * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
      [SVProgressHUD dismiss];
       [SVProgressHUD showSuccessWithStatus:@"清理成功"];
});

参考例子

posted @ 2016-07-27 15:30  tomandhua  阅读(3309)  评论(0编辑  收藏  举报