使用比例变换与边界操作调整 CATiledLayer 的大小
我已经让我的图层托管工作区正常工作,因此当工作区大幅缩小时,使用 CATiledLayers 处理数百个图像可以很好地工作。所有图像都使用较低分辨率的表示形式,并且在平移和缩放大量图像时,我的应用程序的响应速度要快得多。
但是,在我的应用程序中,我还为用户提供了使用调整大小手柄调整图层大小的功能。在我将图像层转换为使用 CATiledLayers 之前,我通过根据调整大小增量(鼠标拖动)操作图像层的边界来调整图层大小,并且效果很好。但现在有了 CATiledLayers,当我通过边界操作混合调整图层大小以及通过比例变换缩放/取消缩放工作区时,这会导致 CATiledLayers 感到困惑。
具体来说,如果我将 CATiledLayer 的大小调整为宽度/高度大小的一半(区域的 1/4),则其中的图像将突然缩放到调整大小后的帧的 1/2,从而使帧的 3/4 为空。这似乎正是调用内部 CATiledLayer 逻辑以提供较低分辨率图像表示的时间。如果我不触摸调整大小处理程序而只是缩放/取消缩放工作区,它就可以正常工作。
有没有办法让缩放/调整大小与 CATiledLayers 一起很好地发挥作用,或者我是否必须将我的图层调整大小逻辑转换为使用缩放变换而不是边界操作?
I've got my layer hosted workspace working so that using CATiledLayers for hundreds of images works nicely when the workspace is zoomed out substantially. All the images use lower resolution representations, and my application is much more responsive when panning and zooming large numbers of images.
However, within my application I also provide the user the ability to resize layers with a resize handle. Before I converted image layers to use CATiledLayers I was doing layer resizes by manipulating the bounds of the image layer according to the resize delta (mouse drag), and it worked well. But now with CATiledLayers in place, this is causing CATiledLayers to get confused when I mix resizing of layers through bounds manipulation and zooming/unzooming the workspace through scale transforms.
Specifically, if I resize a CATiledLayer to half the width/height size (1/4 the area), the image inside it will suddenly scale to a further 1/2 the resized frame leaving 3/4 of the frame empty. This seems to be exactly when the inner CATiledLayer logic gets invoked to provide a lower resolution image representation. It works fine if I don't touch the resize handler and just zoom/unzoom the workspace.
Is there a way to make zooming/resizing play nice together with CATiledLayers, or am I going to have to convert my layer resize logic to use scale transforms instead of bounds manipulations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终通过将我的图层调整大小逻辑转换为使用缩放变换来解决这个问题,方法是重写我的自定义图像图层类的 setBounds: 方法来缩放它包含的 CATiledLayer,并相应地重新定位。另外,确保 CATiledLayer 的 autoresizingMask 设置为 kCALayerNotSizing 也很重要,因为我们在 setBounds: 中手动处理大小调整。
注意:一定要调用超类的 setBounds: 实现。
I ended up solving this by converting my layer resize logic to use scale transforms by overriding the setBounds: method for my custom image layer class to scale it's containing CATiledLayer, and repositioning accordingly. Also it is important to make sure the CATiledLayer's autoresizingMask is set to kCALayerNotSizable since we are handling resizes manually in setBounds:.
Note: be sure to call the superclass's implementation of setBounds:.