0.05 為延遲時(shí)間,可調(diào)
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(), ^{
? ? ? ? ? ? ? ? ? ? ? ? ? ????? //在這里執(zhí)行相關(guān)代碼
????????????????????????????????NSLog(@"當(dāng)前i ?==== %d",i);? ??????????????????????
? ? ? ? ? ? ? ? ? ? ? ? ? ? ? dispatch_semaphore_signal(semaphore);
?????????????????????});
????????????????dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
????????}
});