Xcode Objective-C | iOS: delay function / NSTimer help?

前端 未结 7 1999
旧巷少年郎
旧巷少年郎 2021-02-01 15:32

So I\'m developing my first iOS application and I need help..

Simple program for now, I have about 9 buttons and when I press the first button, or any button, I just wan

7条回答
  •  迷失自我
    2021-02-01 15:48

    I would like to add a bit the answer by Avner Barr. When using int64, it appears that when we surpass the 1.0 value, the function seems to delay differently. So I think at this point, we should use NSTimeInterval.

    So, the final code is:

    NSTimeInterval delayInSeconds = 0.05;
    
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, delayInSeconds * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
    
    //do your tasks here
    
    });
    

提交回复
热议问题