我正在尝试在新队列中运行任务,然后在此任务完成时通知VC运行performSegueWithIdentifier以传递下一个视图控制器。
在方法按钮中,我有这个电话:
- (IBAction)previewButtonTouchedIn:(id)sender
{
prepareDesign(self.imageToEdit,self.maskImageToPrint,self.drawingView,^(UIImage* imageReturn){
self.previewDesignImage = imageReturn;
[self performSegueWithIdentifier:PREVIEW_SEGUE sender:self];
});
}
和调用的方法包含:
void prepareDesign(UIImage *imageToEdit,UIImage *maskImageToPrint,UIView *drawingView, void (^block)(UIImage*)
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
//Here the task which I want to run in a new queue
UIImage *imageSnapShot = [UIImage imageWithCGImage:imageRef];
CGImageRelease(imageRef);
//I have tested with dispatch_sync and dispatch_async.
dispatch_sync(dispatch_get_main_queue(), ^{ block(imageSnapShot);});
});
}
我已经测试了
[[NSOperationQueue mainQueue] addOperationWithBlock:^{ block(imageSnapShot);}];
而不是
dispatch_sync(dispatch_get_main_queue(), ^{ block(imageSnapShot);});
我已经使用断点检查performSegueWithIdentifier
是否运行主线程在performSegueWithIdentifier
调用和prepareForSegue:sender:
中设置断点。
屏幕被冻结。有什么想法吗?
答案 0 :(得分:0)
最后,问题似乎是内部的问题:
//这是我想在新队列中运行的任务
我所有的考试都让我觉得问题是:
[self.drawingView drawViewHierarchyInRect:viewPrintBase.bounds afterScreenUpdates:YES];
很抱歉没有写下所有代码:S
谢谢!