视网膜和非视网膜设备上的renderInContext

dan*_*ard 7 objective-c calayer uikit quartz-core

我通过拍摄UIView的截图来创建PDF,目前在带有视网膜显示屏的iPad3上工作得很好,但是当在其他具有较低分辨率屏幕的设备上进行测试时,我遇到文本分辨率问题.

这是我的代码:

    //start a new page with default size and info
    //this can be changed later to include extra info.
    UIGraphicsBeginPDFPage();

    //render the view's layer into an image context
    //the last option specifies scale. If 0, it uses the devices scale.
    UIGraphicsBeginImageContextWithOptions(view.bounds.size, view.opaque, 2.0);

    CGContextRef context = UIGraphicsGetCurrentContext();
    [view.layer renderInContext:context];
    UIImage *screenShot = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();

    //render the screenshot into the pdf page CGContext
    [screenShot drawInRect:view.bounds];

    //close the pdf context (saves the pdf to the NSData object)
    UIGraphicsEndPDFContext();
Run Code Online (Sandbox Code Playgroud)

我也尝试将UIGraphicsBeginImageContextWithOptions比例设置为2.0,但这没有任何变化.如何强制iPad2上的视图以2倍的分辨率渲染?

预期产量:

Imgur

实际产量:

Imgur

dan*_*ard 5

我最终通过递归地将contentScaleFactor父视图及其子视图的属性设置为2.0 来修复此问题.

UIImage以正确的分辨率渲染,但该层不是在renderInContext被调用时.