如何防止CATiledLayer的子图层CALayer在缩放后更改其比例? [英] How do I keep a CALayer, sublayer of a CATiledLayer, from changing it's scale after a zoom?

查看:113
本文介绍了如何防止CATiledLayer的子图层CALayer在缩放后更改其比例?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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.

因此,在图形上,我有:(请记住,我有多个标记也是CALayers,

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| |       |
|  |  +----+ |       |
|  +---------+       |
|                    |
----------------------

我在视图中设置了标准的drawLayer:inContext:以绘制pdf。

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

当我缩放以获取更多细节时,将渲染pdf正确,但标记已缩放。无论我对CALayer的范围做什么,我的标记始终会变大并出现锯齿。

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.

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

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.

推荐答案

标记正在缩放,因为它继承了超层的变换。创建另一个顶级 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.

这篇关于如何防止CATiledLayer的子图层CALayer在缩放后更改其比例?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆