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:@"清理成功"];
});

参考例子


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM