zoukankan      html  css  js  c++  java
  • 延迟执行的几种方法

    第一种:

      [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秒,再把任务提交到队列中执行。

  • 相关阅读:
    Unity3D Editor模式下批量修改prefab
    3D touch在Unity3D中的使用
    Unity中的协程是什么?
    Unity3D脚本调用Objective C代码实现游戏内购买
    WindowsPhone8拍照功能实现简介
    WindowsPhone App如何扩展能够使用的内存
    SVN 提交代码时提示文件已经存在解决办法
    iOS检查App新版本并更新新版本
    iOS存储数据字典到沙盒
    统计整个Xcode工程代码行数
  • 原文地址:https://www.cnblogs.com/dashengios/p/10409862.html
Copyright © 2011-2022 走看看