Adding delay between execution of two following lines

前端 未结 7 1721
陌清茗
陌清茗 2020-12-07 13:15

I need to add delay between the execution of two lines in a(same) function. Is there is any favorable options to do this?

Note: I don\'t need two di

7条回答
  •  有刺的猬
    2020-12-07 13:25

    If you're targeting iOS 4.0+, you can do the following:

    [executing first operation];
    double delayInSeconds = 2.0;
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        [executing second operation];
    });
    

提交回复
热议问题