Vector like drawing for zoomable UIScrollView

后端 未结 1 1057
隐瞒了意图╮
隐瞒了意图╮ 2020-12-15 14:10

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 the

相关标签:
1条回答
  • 2020-12-15 14:29

    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.

    0 讨论(0)
提交回复
热议问题