用于可缩放 UIScrollView 的矢量绘图

Vector like drawing for zoomable UIScrollView(用于可缩放 UIScrollView 的矢量绘图)
本文介绍了用于可缩放 UIScrollView 的矢量绘图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我有一个可缩放的 UIScrollView,其中包含一些 CATextLayer 和简单的 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)

当视图放大时,我有哪些选项可以使我的文本不模糊?我应该使用其他东西吗?在 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 是因为,正如文档中所建议的那样,CALayerUIViews 轻,而且我有数百个.目前它工作顺利.我尝试过使用 UIWebView 并且我的 CALayer 版本更快;)

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 ;)

提前致谢.

推荐答案

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 的矢量绘图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

UIButtons at the bottom of UIScrollView not working(UIScrollView 底部的 UIButtons 不起作用)
scrollViewWillEndDragging:withVelocity:targetContentOffset: not working on the edges of a UISCrollView(scrollViewWillEndDragging:withVelocity:targetContentOffset: 不在 UISCrollView 的边缘工作)
ImageView Scaling when scrolling down(向下滚动时 ImageView 缩放)
Bounds automatically changes on UIScrollView with content insets(UIScrollView 上的边界自动更改,带有内容插图)
iOS5 UITapRecognizer for UIScrollView interfering with buttons. How to fix?(用于 UIScrollView 的 iOS5 UITapRecognizer 干扰按钮.怎么修?)
How to Cancel Scrolling in UIScrollView(如何在 UIScrollView 中取消滚动)