Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/111.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 转换为pdf时,核心打印图呈现为黑盒_Ios_Objective C_Pdf_Core Plot - Fatal编程技术网

Ios 转换为pdf时,核心打印图呈现为黑盒

Ios 转换为pdf时,核心打印图呈现为黑盒,ios,objective-c,pdf,core-plot,Ios,Objective C,Pdf,Core Plot,我的应用程序使用Core Plot渲染图形,最后需要创建一个pdf文件,应该有这个图形,但当它保存到pdf文件时,我看到的不是图形而是黑匣子。 我用于创建pdf的方法: UIGraphicsBeginPDFContextToFile(outputPath, CGRectZero, nil); for(UIView *view in views) { UIGraphicsBeginPDFPageWithInfo(view.bounds, nil); CGContextRef pd

我的应用程序使用Core Plot渲染图形,最后需要创建一个pdf文件,应该有这个图形,但当它保存到pdf文件时,我看到的不是图形而是黑匣子。 我用于创建pdf的方法:

UIGraphicsBeginPDFContextToFile(outputPath, CGRectZero, nil);

for(UIView *view in views) {
    UIGraphicsBeginPDFPageWithInfo(view.bounds, nil);
    CGContextRef pdfContext = UIGraphicsGetCurrentContext();UIGraphicsBeginPDFContextToFile
    [view.layer renderInContext:pdfContext];
}

UIGraphicsEndPDFContext();
有人能帮我把它渲染好吗

在创建pdf之前,作为一个临时解决方案,我将图形转换为图像,并将其放在其顶部,结果pdf被正确呈现,还有更优雅的解决方案吗

编辑: 我应用了上述建议,代码如下所示:

        if([child isKindOfClass:[CPTGraphHostingView class]]) {
        CGContextTranslateCTM(pdfContext, child.center.x, child.center.y);
        CGAffineTransform transform = CGAffineTransformMakeRotation(0);
        transform.d = -1;

        CGContextConcatCTM(pdfContext, transform);
        CGContextTranslateCTM(pdfContext,
                              child.bounds.size.width * 0.05,
                              -child.bounds.size.height * 0.75);

        CPTLayer *layer = (CPTLayer *)((CPTGraphHostingView *)child).hostedGraph;

        [layer layoutAndRenderInContext:pdfContext];
    }
用户界面上的结果:

结果是pdf:


是否使用部分透明颜色的填充?alpha通道不会渲染为PDF格式。这是Apple PDF框架的一个长期问题。

Skotch,我将其创建为-(void)viewDidLoad{[super viewDidLoad];CPTGraph*graph=[[CPTXYGraph alloc]initWithFrame:_graphView.bounds];self.graphView.hostedGraph=graph;但正如我在调试时看到的,这个黑色的绘图是用CPTXYGraph绘制的。因为所有图形所在的视图都是白色的,而且图形本身也能正确渲染,因为我知道这个地方是弱小的,它造成了这个问题。您需要使用
-layoutanderincontext:
来渲染图形层。这将以正确的顺序呈现图形及其所有子层。感谢Erik的建议,但因此我面临同样的问题,我已更新了该问题。我仍然对此感到困惑。如果您没有在图形上设置
填充
,请执行该操作。默认填充为
nil
,允许通过onsc显示背景视图绿色,但未呈现为PDF格式。
graph.fill=[CPTFill fillWithColor:[CPTColor whiteColor]];
不幸的是,它对CPTGraph*graph=[CPTXYGraph alloc]initWithFrame:[u graphView.bounds];graph.fill=[CPTFill fillWithColor:[cplor whiteColor]];graph.backgroundColor=[UIColor whiteColor]CGColor];self.graphView.hostedGraph=图形;结果仍然相同->黑盒