我无计可施。我已经尝试了我认为的一切来摆脱CATextLayer
模糊无济于事。诚然,有些东西会有所帮助,但是当放大 2 倍时,文本仍然过于模糊,远不及非CATextLayer
文本的清晰度。
这是我的情况。我有一个层托管的视图,它可以包含许多子层,包括CATextLayers
(在自定义CALayer
容器内)。现在,用户可以缩放主内容层(包含所有子层内容),这是通过对内容层应用缩放变换来完成的。
这是我目前正在做的事情。大多数都会有所作为,尽管差别不大。如果我一直放大(这是 2 倍比例因子),我会得到严重模糊的文本。
确保积分坐标 - 工作并产生明显的差异,但在 2 倍比例下仍然过于模糊
关闭
CATextLayer
容器层上的阴影 - 虽然不是 2 倍规模,但会有所不同确保文本层的背景颜色完全不透明 - 尽管不是 2 倍比例,但似乎有所不同
将
contentsScale
属性设置为所有图层的窗口支持比例因子 - 尽管不是 2 倍比例,但似乎有所不同覆盖
-drawInContext:
此自定义CATextLayer
子类以平滑、抗锯齿和子像素量化一切 - 字体渲染更真实,但在 2 倍比例下仍然模糊
代码片段:
- (void) drawInContext:(CGContextRef)context
{
// Allow font smoothing.
CGContextSetAllowsAntialiasing(context, YES);
CGContextSetAllowsFontSmoothing(context, YES);
CGContextSetAllowsFontSubpixelPositioning(context, YES);
CGContextSetAllowsFontSubpixelQuantization(context, YES);
// Set drawing attributes.
CGContextSetStrokeColorWithColor(context, self.foregroundColor);
CGContextSetFillColorWithColor(context, self.backgroundColor);
CGContextFillRect(context, self.bounds);
// Font smoothing.
CGContextSetShouldAntialias(context, YES);
CGContextSetShouldSmoothFonts(context, YES);
CGContextSetShouldSubpixelPositionFonts(context, YES);
CGContextSetShouldSubpixelQuantizeFonts(context, YES);
[super drawInContext:context];
}
我错过了什么?