防止 CALayer 子层缩放
我在图层托管视图中有一些 CALayers。这些层中的每一层都有附加层来容纳 (1) 关闭按钮和 (2) 调整大小手柄。这些附加的“控制”图层作为子图层添加到父图层中。
目前,当我缩放这些图层所在的工作区时,所有内容都会缩放 - 包括这些控制图层。但是,我想防止这些控制层缩放。
有没有办法覆盖将缩放变换应用于所有子层的行为,而不必覆盖每个控制层的drawInContext:方法(大概反转任何现有的缩放变换 - 假设这是可能的)并且无需手动每次缩放时都会向每个控制层发送 setNeedsDisplay: ?
我发现这个线程讨论了类似的事情,但讨论朝着 CATiledLayers 的方向进行,这不是我在这里寻找的。
另外,这篇文章提出了一个有些相关的问题,但答案不适用于我的情况,因为我无法覆盖控件——它们必须是图层层次结构的一部分。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终通过重写自定义 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.