iOS 延时

2019-08-29  本文已影响0人  溪小希

1 NSTimer

    //1秒后执行

    NSTimer *timer = [NSTimer timerWithTimeInterval:1 target:self selector:@selector(_doTimer:) userInfo:nil repeats:NO];

2 系统

    //延迟1s执行

    [self performSelector:@selector(_doTimer:) withObject:nil afterDelay:1];

3 GCD

    /**

    *  异步执行 好处在于经度高

    *  参数1:延时的时间 dispatch_time 生成时间 纳秒为计数单位

    *  参数2:队列

    *  参数3:任务  并且异步执行

    *  block 里边是延迟后执行的方法

    */

    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1*NSEC_PER_SEC)), dispatch_get_main_queue(), ^{                            [self_task];

    });

原文: https://www.jianshu.com/p/577cd6842140

上一篇 下一篇

猜你喜欢

热点阅读