绘制图像时 UITextview 模糊

问题描述

当我绘制新图像时,uitextview 模糊。

绘制新图像后的第一个文本。看起来很模糊。

第二个文本被捕获

enter image description here

我试过这个 anwser 将帧更改为整数。

UITextField blurred text

在绘制新图像之前它可以工作,但是在绘制图像时它不起作用。

这是我的代码

// UIView -> UIImage
convenience init(view: UIView) {
        UIGraphicsBeginImageContextWithOptions(view.bounds.size,view.isOpaque,0)
    view.drawHierarchy(in: view.bounds,afterScreenUpdates: true)
    
    let image = UIGraphicsGetImageFromCurrentImageContext()!
    UIGraphicsEndImageContext()
    
    self.init(cgImage: image.cgImage!)
}

解决方法

将 textview 的优先级设置为比通常值更高的值。

,

我通常为 UIGraphicsBeginImageContextWithOptions 指定比例值

UIGraphicsBeginImageContextWithOptions(bounds.size,false,UIScreen.main.scale)

但是 0 也应该有效。在 Apple 文档中,使用 0.0 作为比例值来使用设备比例值(就像我手动设置的那样) - 也许在当前位置 0 与 0.0 不一样的零? :)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...