CATextLayer子像素抗锯齿 [英] CATextLayer subpixel antialiasing

查看:665
本文介绍了CATextLayer子像素抗锯齿的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序在 NSImageView 上绘制了图层标签。

图像视图显示图像,并在该图像上显示色调。 / p>

这可确保标签和背景图片之间的对比效果。





如您所见,子像素抗锯齿已启用并正常工作。



当您将鼠标悬停在这些标签上时,它们将对框架属性(实际上是包含它们的视图)进行动画处理。 br>
当动画处理时,子像素抗锯齿处于禁用状态,并且再次启用时。





这看起来很奇怪。



图层从不重绘,子像素抗锯齿不必改变。

所以我没有看到一个很好的理由动画时不应显示。



我尝试了所有我能想到的。




  • 使 NSTextField 不透明

  • 使 CATextLayer

  • 给予 NSTextField 背景颜色

  • CATextLayer 背景颜色



总是相同的结果。



禁用对标签的子像素抗锯齿不是一个选项,因为它在非视网膜设备上的可读性不好。






EDIT



我在动画时忘记了图层被替换为 presentationLayer

这个层可能不支持子像素抗锯齿,这就是为什么它被禁用。

现在的问题是如果我可以替换 presentationLayer

code>与 CATextLayer



我还注意到,将 shouldRasterize 设置为 YES 启用子像素抗锯齿也用于动画,但只针对背景颜色。因此没有背景颜色不会带来子像素抗锯齿。

解决方案

有什么办法可以发布一段示例代码吗?我快速模拟了一个NSWindow,添加了一个NSImageView,添加了一个无背景的NSTextField与setWantsLayer:设置为YES。在我的applicationDidFinishLaunching:我在NSTextField的Animator框架上设置了一个新的rect,但我没有看到任何像素化。


My app draws layer-backed labels over a NSImageView.
The image view displays an image, and a tint color over that image.

This ensures that the contrast between the labels and the background image works.

As you can see, subpixel antialiasing is enabled and works correctly.

When you hover over those labels, they animate the frame property (Actually the view containing them).
While animating, the subpixel antialiasing is disabled, and when done enabled again.

This looks incredibly weird.

The layer is never redrawn, and the subpixel antialiasing doesn't have to change.
So I don't see a good reason why it shouldn't be displayed when animating.

I've tried everything I can think of.

  • Making the NSTextField opaque
  • Making the CATextLayer opaque
  • Giving the NSTextField a background-color
  • Giving the CATextLayer a background-color

Always the same result.

Disabling subpixel antialiasing for the labels is not an option, since it's not well readable on non-retina devices.


EDIT

I forgot that the layer is replaced with a presentationLayer while animating.
This layer probably does not support subpixel antialiasing, which is why it's disabled.

Now the question is if I can replace this presentationLayer with a CATextLayer.

What I also noticed is that setting shouldRasterize to YES enabled subpixel antialiasing also for animation, but only against the background color. So no background-color will bring no subpixel antialiasing.

解决方案

Is there any way that you can post a piece of sample code? I quickly mocked up an NSWindow, added an NSImageView, added a background-less NSTextField with setWantsLayer: set to YES. In my applicationDidFinishLaunching: I set a new rect on the NSTextField's Animator frame, but I didn't see any pixelation.

这篇关于CATextLayer子像素抗锯齿的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆