三種常見的延時執行方式
- GCD
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(多少秒 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
// 需要延時執行的任務
});
方便靈活,可以
隨意使用
。performSelector方法族
[self performSelector:@selector(workPostponed:) withObject:nil afterDelay:多少秒];
當前線程必需啟動
run loop
。NSThread
[NSThread sleepForTimeInterval:多少秒];
- 延遲期間,當前線程被
阻塞
。