CALayer Antialiasing不如UIView抗锯齿 [英] CALayer Antialiasing not as good as UIView antialiasing

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

问题描述

我一直在尝试使用CALayer为圆形绘图添加动画效果。这一切都运作良好,但问题是 - 绘制圆圈不足以抗锯齿。它有一个太粗糙的边框,(如果使用栅格化,则会模糊)。 (已启用AntiAliasing)

I've been trying to animate circle drawing using CALayer. It all works well, but the problem is - drawn circle is not antialiased enough. It has a bit too rough borders, (or blurred if rasterize is used). (AntiAliasing is enabled)

还尝试:


edgeAntialiasingMask = kCALayerLeftEdge | kCALayerRightEdge |
kCALayerBottomEdge | kCALayerTopEdge;

edgeAntialiasingMask = kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge;

无济于事。

以下是一个例子如何看似没有光栅化:

Here is an example how it looks like without rasterization:

以下是光栅化的示例:(尝试从1.0到4.0的值(只是为了确定。结果 - 相同。)

And here is an example with rasterization: (tried values from 1.0 till 4.0 (just to be sure. Result - the same.))

这是相同的圆圈,但是绘制在UIView内部:

And here is the same circle, but drawn inside UIView drawrect:

你可以看到,使用UIView drawrect绘制的圆圈看起来好多了。

You can see, that circle drawn using UIView drawrect is looking much better.

我无法使用的原因UIView是因为我需要为圆形填充动画。使用CALayer非常简单,但是在UIView上做同样的事情,我真的不知道它是否可能。 (我可以尝试启动drawrect:每1/60秒,但我认为它会变得迟钝,因为它不是那样的。)

The reason I cannot use UIView is because I need to animate circle filling. Using CALayer it is really easy, but to do the same on UIView, I don't really know if it is even possible. (I could try to launch drawrect: every 1/60 seconds, but I think it will get laggy, as it is not intended that way).

所以 - 有没有人有任何解决方案如何在CALayer上绘制圆圈/线条与UIView上绘制的相同?

推荐答案

我之前在视网膜设备上的 CALayer 中存在像素化绘图问题。 (我假设您在视网膜设备上看到了问题)执行以下操作修复了我遇到的问题:

I've had issues with pixelated drawing in a CALayer on retina devices before. (I'm assuming you're seeing the issue on retina devices) Doing the following fixed the issue I was experiencing:

layer.contentsScale = [[UIScreen mainScreen] scale];

您不需要处理光栅化或抗锯齿。在我自己的代码中,我最初实现了绘制到 UIView 的东西,后来我改为绘制在 CALayer 中,只需设置 contentsScale 属性,两者都相同。

You shouldn't need to deal with rasterization or antialiasing. In my own code, I had initially implemented drawing something to a UIView that I later changed to be drawn in a CALayer, and simply setting the contentsScale property made both draw identically.

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

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