如何防止 CALayer(CATiledLayer 的子层)在缩放后更改其比例?

发布于 2024-09-04 16:10:10 字数 756 浏览 12 评论 0原文

我有一个用于显示 PDF 页面的 CATiledLayer(此 CATiledLayer 是我的 UIView 的图层类型,它是 UIScrollView 的子视图)。我想在此页面上添加覆盖标记。因此,我将一个子层添加到我的 CATiledLayer 中。该子层再次托管不同标记的层并充当分组层。

所以从图形上讲,我有:(请记住,我有多个标记,它们也是 CALayers,这毕竟是 ascii 艺术)

pdf page (CATiledLayer)
----------------------
|  CALayer           |
|  +---------+       |
|  |  +----+ |       |
|  |  |mker| |       |
|  |  +----+ |       |
|  +---------+       |
|                    |
----------------------

我已经在我的视图中设置了规范的 drawLayer:inContext: 来绘制 pdf。

当我缩放以获得更多细节时,pdf 会正确渲染,但标记会缩放。无论我对 CALayer 的边界做什么,我的标记总是会变得更大并且呈现锯齿状。

我希望标记始终具有相同的大小,就像它们初始化并在绘制视图时首次显示时一样。这可能吗?或者我使用了错误的方法?我应该在drawLAyer:inContext: 消息中为我包含的CALayer 进行特殊绘制吗?

如您所见,我缺少一些东西来解决我的问题。感谢您提供的任何帮助。

I have a CATiledLayer that is used to display a PDF page (this CATiledLayer is the layer type of my UIView which is a subview of a UIScrollView). I want to add overlay markers on this page. So I add a sublayer to my CATiledLayer. This sublayer again hosts the different marker's layers and acts as a grouping layer.

So graphically, I have: (keep in mind that I have multiple markers which are CALayers also, this is ascii art after all)

pdf page (CATiledLayer)
----------------------
|  CALayer           |
|  +---------+       |
|  |  +----+ |       |
|  |  |mker| |       |
|  |  +----+ |       |
|  +---------+       |
|                    |
----------------------

I have set up the canonical drawLayer:inContext: in my view for drawing the pdf.

When I zoom to have more detail, the pdf gets rendered correctly, but the markers get scaled. No matter what I do to the bounds of the CALayer, my markers always become bigger and appear jagged.

I would like to have the markers always the same size, as when they were initialized and first shown when the view was drawn. Is this possible ? or am I using a wrong approach ? Should I do special drawing for my contained CALayer in the drawLAyer:inContext: message ?

As you see, there are things that I am missing to resolve my problem. Thank you for any help you provide.

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

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

发布评论

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

评论(1

徒留西风 2024-09-11 16:10:10

标记正在缩放,因为它继承了超级层的变换。创建另一个顶级 CALayer,其中包含您不希望缩放的标记和其他对象,并将其覆盖在 CATiledLayer 之上。

The marker is scaling because it inherits the transforms of the superlayer. Create another top level CALayer that contains the markers and other objects you don't want scaled and overlay it on top of CATiledLayer.

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