用于可缩放 UIScrollView 的矢量绘图

发布于 2024-10-29 11:50:17 字数 358 浏览 0 评论 0原文

我有一个可缩放的 UIScrollView,其中包含一些 CATextLayer 和简单的 CALayer。 它们渲染得很好,但问题是当它们缩放时,它们会变得模糊。 (即使我重新绘制它们)

当视图缩放时,我可以选择什么来使文本不模糊? 我应该使用其他东西吗?启用 CATextLayer/CALayer 中的某些内容?欢迎任何想法;)

我使用 CALayer 是因为,正如文档中所建议的, CALayer 比 UIViews 更轻,而且我有数百个他们。目前运行顺利。我尝试过使用 UIWebView ,我的 CALayer 版本更快;)

提前致谢。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

流殇 2024-11-05 11:50:17

iOS 在放大之前对文本进行光栅化,这就是它如此模糊的原因。您只需要修复 CATextLayer 的一个属性,contentsScale,即可在缩放后获得更高质量的渲染。实现此 UIScrollViewDelegate 方法:

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

这告诉图层使用更多像素来渲染文本,并在进行特定更改时禁用核心动画。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文