Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/22.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 drawViewHierarchyInRect打印全黑图像_Ios_Objective C_Uiwebview_Uiimage_Ipod - Fatal编程技术网

Ios drawViewHierarchyInRect打印全黑图像

Ios drawViewHierarchyInRect打印全黑图像,ios,objective-c,uiwebview,uiimage,ipod,Ios,Objective C,Uiwebview,Uiimage,Ipod,我有一个我正试图打印的网页视图,当我加载一个很长(超过一页)的网页时,它会打印成黑色。我无法使用RenderContext方法,因为当我尝试打印页面时,由于内存问题,它会使应用程序崩溃。我正在使用dymo收据打印机 这是我的代码 + (UIImage*)viewToImage:(UIView*)theView { UIImage *image = nil; // Save current bounds so we can reset them laster CGRect

我有一个我正试图打印的网页视图,当我加载一个很长(超过一页)的网页时,它会打印成黑色。我无法使用RenderContext方法,因为当我尝试打印页面时,由于内存问题,它会使应用程序崩溃。我正在使用dymo收据打印机

这是我的代码

+ (UIImage*)viewToImage:(UIView*)theView
{
    UIImage *image = nil;

    // Save current bounds so we can reset them laster
    CGRect tmpFrame = theView.frame;
    CGRect tmpBounds = theView.bounds;

    // Adjust the bounds of the webview so we can take a screen shot of the entire view, even if its scrolled off screen.
    CGRect aFrame = theView.bounds;
    aFrame.size.width = theView.frame.size.width;
    aFrame.size.height = theView.frame.size.height;
    theView.frame = aFrame;
    aFrame.size.height = [theView sizeThatFits:[[UIScreen mainScreen] bounds].size].height;
    theView.frame = aFrame;


    UIGraphicsBeginImageContextWithOptions(theView.bounds.size, NO, 1.8);

    [theView drawViewHierarchyInRect:theView.bounds afterScreenUpdates:YES];

    // crashes the app [self.layer renderInContext:UIGraphicsGetCurrentContext()];

    image = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    return image;
}