矢量像可缩放的UIScrollView绘图 [英] Vector like drawing for zoomable UIScrollView
问题描述
我有一个可缩放的UIScrollView,里面有一些 CATextLayer
和简单的 CALayer
。
它们被渲染得很好,但问题是当它们被缩放时它们会变得模糊。 (即使我重绘它们)
I have a zoomable UIScrollView with some CATextLayer
s and simple CALayer
s in it.
They get rendered fine but the problem is when they are zoomed they become blurry. (Even if I redraw them)
当缩放视图时,我的选项是什么让我的文字不模糊?
我应该用另一件东西吗?在 CATextLayer
/ CALayer
中启用某些内容?欢迎任何想法;)
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 ;)
我使用 CALayer
s因为,正如文档中所建议的, CALayer
s比 UIViews
轻,我有数百个。目前它运作顺利。我尝试过 UIWebView
而我的 CALayer
版本更快;)
I am using CALayer
s because, as suggested in documentation, CALayer
s 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 ;)
提前致谢。
推荐答案
iOS在放大之前光栅化文本,这就是它如此模糊的原因。您只需要修复CATextLayer的一个属性contentsScale,即可在缩放后获得更高质量的渲染。实现这个UIScrollViewDelegate方法:
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.
这篇关于矢量像可缩放的UIScrollView绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!