防止 CALayer 子层缩放

发布于 2024-09-14 15:22:50 字数 676 浏览 2 评论 0原文

我在图层托管视图中有一些 CALayers。这些层中的每一层都有附加层来容纳 (1) 关闭按钮和 (2) 调整大小手柄。这些附加的“控制”图层作为子图层添加到父图层中。

目前,当我缩放这些图层所在的工作区时,所有内容都会缩放 - 包括这些控制图层。但是,我想防止这些控制层缩放。

有没有办法覆盖将缩放变换应用于所有子层的行为,而不必覆盖每个控制层的drawInContext:方法(大概反转任何现有的缩放变换 - 假设这是可能的)并且无需手动每次缩放时都会向每个控制层发送 setNeedsDisplay: ?

我发现这个线程讨论了类似的事情,但讨论朝着 CATiledLayers 的方向进行,这不是我在这里寻找的。

缩放超级图层时重绘 CALayer 子类

另外,这篇文章提出了一个有些相关的问题,但答案不适用于我的情况,因为我无法覆盖控件——它们必须是图层层次结构的一部分。

如何防止 CALayerCATiledLayer 的子层)更改其比例缩放后?

I have some CALayers in a layer hosted view. Each of these layers has additional layers to hold (1) a close button, and (2) a resize handle. These additional 'control' layers are added as sublayers to the parent layer.

Currently, when I zoom the workspace in which these layers reside, everything scales -- including these control layers. However, I would like to prevent these control layers from scaling.

Is there a way to override the behaviour of having scale transforms being applied to all sublayers, without having to override the drawInContext: method for each control layer (presumably to invert any existing scale transform -- assuming this is possible) and without having to manually send each of these control layers a setNeedsDisplay: with every zoom?

I found this thread which discusses doing something similar but the discussion goes in the direction of CATiledLayers which is not what I'm looking for here.

Redrawing CALayer subclass when super layer is scaled

Also, this post asks a somewhat related question but the responses do not apply to my situation, since I cannot overlay the controls -- they must be part of the layer hierarchy.

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

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

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

发布评论

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

评论(1

浅忆流年 2024-09-21 15:22:50

我最终通过重写自定义 CALayers 的 layoutSublayers 方法、获取图层层次结构的累积比例变换并将逆变换应用于控制子图层来解决了这个问题。

I ended up solving this problem by overriding the layoutSublayers method of my custom CALayers, obtaining the accumulated scale transform of the layer hierarchy, and applying the inverse transform to the control sublayers.

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