iPhone - 将透视图应用于 CALayer 时出现锯齿状边缘

iPhone - Jagged Edges when applying perspective to CALayer(iPhone - 将透视图应用于 CALayer 时出现锯齿状边缘)

本文介绍了iPhone - 将透视图应用于 CALayer 时出现锯齿状边缘的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 CALayer,我将透视应用到使用 CGTransform3D 并指定 m14 属性.应用透视时,图层的边缘呈锯齿状.我听说有人提到在图层周围添加一个 1px 的透明边框会有所帮助.我不知道该怎么做.我尝试使用 CALayer 的 borderborderWidth 属性,但锯齿状边缘仍然存在.我还尝试将在所有边上绘制 1px 的矩形减小,但这也无济于事.

I have a CALayer that I apply a perspective to using a CGTransform3D and specifying the m14 property. When the perspective is applied, the layer has jagged edges. I've heard people mention that adding a 1px transparent border around the layer will help with this. I don't know how to do that. I have tried using the border and borderWidth properties of a CALayer but the jagged edges are still there. I also tried to reduce the rect that is drawn by 1px on all sides, but it doesn't help either.

任何帮助都会很棒!谢谢!

Any help would be great! Thanks!

推荐答案

我听说有人提到过",我假设你的意思是 这个问题.建议使用代码在 CALayer 中实际绘制内容,使其在核心内容之外具有一个像素的透明边框

By "I've heard people mention," I assume you mean the discussion on this question. What was suggested there was to actually draw the content in your CALayer so that it has a one-pixel transparent border outside of the core content, using the code

CGContextSetAllowsAntialiasing(theContext, true);
CGContextSetShouldAntialias(theContext, true);

在该层的 Quartz 绘图中.

within your Quartz drawing for that layer.

CALayer 上还有 edgeAntialiasingMask 属性,但我在使用如下代码时没有看到任何影响:

There's also the edgeAntialiasingMask property on CALayer, but I've seen no impact when using code like the following:

layer.edgeAntialiasingMask = kCALayerLeftEdge | kCALayerRightEdge | kCALayerBottomEdge | kCALayerTopEdge;

关于变换层边缘的抗锯齿.另请参阅 this question 以了解有关此问题的讨论以及它们如何解决了他们在图像周围使用一像素透明边框的问题.

on the antialiasing of transformed layer edges. See also this question for discussion of this, as well as how they solved their problem using one-pixel transparent borders around their images.

这篇关于iPhone - 将透视图应用于 CALayer 时出现锯齿状边缘的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:iPhone - 将透视图应用于 CALayer 时出现锯齿状边缘

基础教程推荐