Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
382 views
in Technique[技术] by (71.8m points)

iphone - Vector like drawing for zoomable UIScrollView

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...