How do I keep a CALayer, sublayer of a CATiledLayer, from changing it's scale after a zoom?

自闭症网瘾萝莉.ら 提交于 2019-12-21 19:52:31

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/2985763/how-do-i-keep-a-calayer-sublayer-of-a-catiledlayer-from-changing-its-scale-af

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!