I have problem related with question
I’ve set contentsScale and after that text looking good but if I apply the 3d rotation transformation the text comes out blurry.
image here
initialization code
// init text
textLayer_ = [CATextLayer layer];
…
textLayer_.contentsScale = [[UIScreen mainScreen] scale];
// init body path
pathLayer_ = [CAShapeLayer layer];
…
[pathLayer_ addSublayer:textLayer_];
rotation code
// make the mirror
pathLayer_.transform = CATransform3DRotate(pathLayer_.transform, M_PI, 0, 1, 0);
textLayer_.transform = CATransform3DRotate(textLayer_.transform, M_PI, 0, 1, 0);
[textLayer_ setNeedsDisplay];
For test i’ve rotated text separately during the initialization.
// init text
textLayer_ = [CATextLayer layer];
…
textLayer_.transform = CATransform3DRotate(textLayer_.transform, M_PI, 0, 1, 0);
textLayer_.contentsScale = [[UIScreen mainScreen] scale];
Text can be rotated and remains clear
image here
Rasterizing
What’s probably happening here is that it decides it has to render the textLayer to pixels. Note the warning for shouldRasterize in the CALayer Class Reference:
So, CATextLayer may suddenly decide to rasterize. It decides to rasterize if it’s a sublayer of a rotated layer. So, don’t make that happen.
Single-Sided Layers
That takes you back to your solution that causes the reversed text. You can prevent this by turning off
doubleSidedon the text layers. Your signs will now be blank on the far side, so add a second text layer, rotated 180 degrees relative to the first.Declare two text layers:
Then, initialize them to be single-sided, with the back layer rotated 180 degrees:
You can then rotate the layers. They will appear correct as long as you always rotate by the same amount.
You should then find that you can rotate your sign to any angle while the text remains sharp.
Text to Path
There is an alternative, if you really need to manipulate your text display in ways that cause CATextLayer to rasterize: convert the text to a
UIBezierPathrepresentation. This can then be placed in a CAShapeLayer. Doing so requires delving deep into Core Text, but the results are powerful. For example, you can animate the text being drawn.Here is rotating outlined text, created with the method above. It was also possible to add perspective without the z positions of the text layers becoming apparent.