Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/113.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
iOS:我可以在全局队列上截图吗?_Ios_Screenshot - Fatal编程技术网

iOS:我可以在全局队列上截图吗?

iOS:我可以在全局队列上截图吗?,ios,screenshot,Ios,Screenshot,我想知道如何在全球队列中截图?现在,我在主队列中执行,它可以工作,如果我在全局队列中执行,事情就会冻结。我正在使用以下截图代码: 我还尝试了以下代码来拍摄self.view的快照,但它也不起作用: +(UIImage *)snapshot_of_view:(UIView*)view { UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale); [view.l

我想知道如何在全球队列中截图?现在,我在主队列中执行,它可以工作,如果我在全局队列中执行,事情就会冻结。我正在使用以下截图代码: 我还尝试了以下代码来拍摄self.view的快照,但它也不起作用:

+(UIImage *)snapshot_of_view:(UIView*)view {
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
    [view.layer renderInContext:UIGraphicsGetCurrentContext()];
    UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return image;
}

任何想法?

任何UI操作必须在调用用户界面代码的主线程中执行。UI代码必须在主线程上,因为该线程具有主运行循环和其他内容

您需要在主线程上执行此操作:

+(UIImage *)snapshot_of_view:(UIView*)view {
    dispatch_async(dispatch_get_main_queue(), ^{
        UIGraphicsBeginImageContextWithOptions(view.bounds.size, NO, [UIScreen mainScreen].scale);
        [view.layer renderInContext:UIGraphicsGetCurrentContext()];
        UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        return image;
    });
}
我看到这篇文章()说UIGraphicsBeginImageContext是线程安全的,这是否意味着我可以在任何线程上执行UI..context?