0.05 为延迟时间,可调
dispatch_queue_t serialQueue = dispatch_queue_create("serialQueue", DISPATCH_QUEUE_SERIAL);
dispatch_async(serialQueue, ^{
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
for (i=0 ; i<100; i++) {
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.05 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//在这里执行相关代码
NSLog(@"当前i ==== %d",i);
dispatch_semaphore_signal(semaphore);
});
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
}
});
网友评论