Skip to content

Instantly share code, notes, and snippets.

@kommen
Created June 9, 2013 14:56
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kommen/5743831 to your computer and use it in GitHub Desktop.
Save kommen/5743831 to your computer and use it in GitHub Desktop.
Queue presentViewController and dismissViewControllerAnimated with dispatch semaphores.
- (void) queueViewControllerTransition:(BOOL)show {
static dispatch_queue_t presentAndDismissViewControllerQueue;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
presentAndDismissViewControllerQueue = dispatch_queue_create("presentAndDismissViewControllerQueue", DISPATCH_QUEUE_SERIAL);
});
dispatch_async(presentAndDismissViewControllerQueue, ^{
dispatch_semaphore_t sema = dispatch_semaphore_create(0);
dispatch_async(dispatch_get_main_queue(), ^{
if (show) {
[self presentViewController:self.yourViewController animated:YES completion:^{
dispatch_semaphore_signal(sema);
}];
} else{
[self dismissViewControllerAnimated:YES completion:^{
dispatch_semaphore_signal(sema);
}];
}
});
dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment