Ios drawViewHierarchyInRect打印全黑图像
我有一个我正试图打印的网页视图,当我加载一个很长(超过一页)的网页时,它会打印成黑色。我无法使用RenderContext方法,因为当我尝试打印页面时,由于内存问题,它会使应用程序崩溃。我正在使用dymo收据打印机 这是我的代码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
+ (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;
}