我的应用程序中有几个 shinobicharts,我想打印成 PDF 文件。其他一切,如普通视图、标签和图像都可以正常工作,甚至显示网格、图例和网格标签。唯一缺少的是系列。所以基本上我得到一个打印到 PDF 文件中的空图表。
我按如下方式打印 PDF:
NSMutableData * pdfData=[NSMutableData data];
PDFPage1ViewController *pdf1 = [self.storyboard instantiateViewControllerWithIdentifier:@"PDF1"];
pdf1.array1 = array1;
pdf1.array2 = array2;
pdf1.array3 = array3;
pdf1.array4 = array4;
UIGraphicsBeginPDFContextToData(pdfData, CGRectZero,nil);
CGContextRef pdfContext=UIGraphicsGetCurrentContext();
UIGraphicsBeginPDFPage();
[pdf1.view.layer renderInContext:pdfContext];
UIGraphicsEndPDFContext();
来自 PDF1PageViewController 的完全相同的代码在普通的 viewController 中绘制了漂亮的图表,而不是缺少系列。数组包含应显示的数据。
[编辑]
这段代码为我做了:
UIGraphicsBeginImageContextWithOptions(pdf1.view.bounds.size, NO, 0.0);
[pdf1.view drawViewHierarchyInRect:pdf1.view.bounds afterScreenUpdates:YES];
UIImage *pdf1Image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
UIImageView *pdf1ImageView = [[UIImageView alloc] initWithImage:pdf1Image];
[pdf1ImageView.layer renderInContext:pdfContext];
尽管活动轮在之后停止旋转,drawViewHierarchyInRect
并且显示当前正在呈现的页面的标签也停止更新。任何人都知道如何解决这个问题?