Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CALayer Antialiasing not as good as UIView 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)

Tried also:

edgeAntialiasingMask = kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge;

to no avail.

Here is an example how it looks like without rasterization: enter image description here

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

enter image description here

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

enter image description here

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

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).

So - does anyone have any solution how I could make drawn circles/lines on CALayer look the same as drawn on UIView?

like image 656
Guntis Treulands Avatar asked Jan 27 '14 22:01

Guntis Treulands


1 Answers

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];

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.

like image 162
Gavin Avatar answered Sep 19 '22 14:09

Gavin