6

I have a zoomable UIScrollView with some CATextLayers and simple CALayers in it. They get rendered fine but the problem is when they are zoomed they become blurry. (Even if I redraw them)

What would be my options to get my text not blurry when the view is zoomed? Should I use another thing? enable something in CATextLayer/CALayer? Any idea is welcomed ;)

I am using CALayers because, as suggested in documentation, CALayers are lighter than UIViews and I have hundreds of them. Currently it works smoothly. I have tried with UIWebView and my CALayer version is faster ;)

Thanks in advance.

nacho4d
  • 43,720
  • 45
  • 157
  • 240

1 Answers1

16

iOS rasterizes the text before the scale-up occurs, that's why it's so blurry. You only need to fix one property of your CATextLayer, contentsScale, to get a higher quality render after zooming. Implement this UIScrollViewDelegate method:

- (void)scrollViewDidEndZooming:(UIScrollView *)scrollView
                       withView:(UIView *)view
                        atScale:(float)scale
{
    [CATransaction begin];
    [CATransaction setValue:[NSNumber numberWithBool:YES] 
                     forKey:kCATransactionDisableActions];
    uglyBlurryTextLayer.contentsScale = scale;
    [CATransaction commit];
}

This tells the layer to use more pixels to render the text, and it disables Core Animation when making that particular change.

pe8ter
  • 1,263
  • 12
  • 10
  • Sorry for the late acceptance. This is what I was looking for. Just great! ;) – nacho4d May 17 '11 at 13:43
  • This doesn't quite work - it changes the size of the rendered text too. As you zoom in, the text gets smaller, as you zoom out, it gets larger (so that the same number of pixels is being used on screen, I think?). – Adam Dec 27 '11 at 01:31
  • I'm not quite sure what you mean. – pe8ter Dec 28 '11 at 00:10