Dispatch_async and UI
I made alert informing user about saving action, i add it to view, save some image and dismiss alert. However it's not working in the way i hoped it would. Looking at code below ofc firstly in console i get "saved.." then "dispath". I would like to get opposite effect firstly get "dispath" then "saved.." (so write alert on screen, then save in background and finally dismiss alert). But i change image of imageView1, so i cant move merging out of dispath_async because its an UI action.. how to do it then..? I need to firstly merge images and after it to save them and all of this calculating time to keep alert in front.
//adding alert to view
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),
^{
dispatch_async(dispatch_get_main_queue(), ^{
//i want this to complete->
imageView1.image = [self merge:imageView1.image and:imageView2.image]开发者_C百科;
NSLog(@"dispatch");
});
//and then to do this action->
UIImageWriteToSavedPhotosAlbum(imageView1.image, self, @selector(imageSavedToPhotosAlbum:didFinishSavingWithError:contextInfo:), nil);
NSLog(@"saved..");
dispatch_async(dispatch_get_main_queue(), ^{
[alert dismissWithClickedButtonIndex:0 animated:YES];
});
});
You should simply use dispatch_sync
instead of dispatch_async
. That function will not return until the block has executed on the main thread.
精彩评论