微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

objective-c – 视网膜和非视网膜设备上的renderInContext

我通过拍摄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();

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

预期产量:

实际产量:

解决方法

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

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

原文地址:https://www.jb51.cc/c/118095.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐