CATiledLayer 和 UIImageView 他们之间有什么大不了的?
几个月前,我从苹果网站找到了一个非常棒的示例代码。该示例称为“LargeImageDownsizing”,美妙之处在于它解释了很多有关如何从资源读取图像然后在屏幕上呈现图像的信息。
深入研究该代码,我发现了一些让我有点不安的东西。缩小尺寸的图像被传递到具有 CATiledLayer 的视图,但没有在每个图块处提供一块图像以提高内存性能,它只是设置图块大小,然后加载图像(我让事情变得简单,以了解概念)。
所以我的问题基本上是为什么?如果没有以正确的方式提供,为什么要使用 CATiledLayer,他们可以使用普通的 UIImageView...
所以我做了一些测试来了解我是否正确。修改代码,简单地添加一个带有图像视图的滚动视图作为子视图,并响应委托滚动视图的缩放。我在设备和 sim 上进行了测试,得出了这些结论:
- - 即使在缩放滚动操作期间,内存影响和占用空间也是完全相同的,这并不令我感到惊讶,图像在内存中解压缩
- -时间配置文件说,在滚动缩放操作期间,平铺视图需要更多时间来绘制,而不是 uiimageview,这并不让我感到惊讶,uiimageview 已经绘制
- -如果我发送内存警告,两个解决方案之间没有任何变化(仅在sim)
- -测试核心动画性能我在 60FPS 左右得到相同的结果
那么这两个视图/层之间有什么关系,为什么在这些特定情况下我应该选择一个而不是另一个? UIImageView 似乎赢得了这场战斗。
我希望有人能帮助我理解这一点。
few months ago I've found a really awesome sample code from Apple site. The sample is called "LargeImageDownsizing" the wonderful thing is that it explain a lot about how image are read from resources and then rendered on screen.
Digging into that code I've found something that is disturbing me a little. The downsized image is passed to a view that has a CATiledLayer, but without giving a piece of image at each tile to improve memory performance, it just set the tile size and then load image (I'm making things simple to go to the concept).
So my question basically is why?Why use a CATiledLayer if it is not feed in the right way, they could have used a normal UIImageView...
So I made few tests to understand if I was right. Modifing the code simple adding a scrollview with an image view as subview and responding to the delegate scrollview for zoom. I went to those conclusions testing on device and sim:
- -The memory impact and footprint is exactly the same, even during zooming scrolling operation and it doesn't surprise me at all, the image is decompressed in memory
- -Time profile say that a tileview take more time to be drawn during scrolling zoom operation instead of a uiimageview and that doesn't surprise me at all again the uiimageview is already drawn
- -If I send memory warning nothing change between the two solution(only on sim)
- -Testing Core Animation performance I get the same results around 60FPS
So what's the deal between those two views/layers why should I pick one instead of the other in these specific case? UIImageView seems to win the battle.
I hope that someone could help me to understand that.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
它们对于小图像可能执行相同的操作,因为操作系统性能方面的唯一区别是 CATiledLayer 在后台线程上绘制。根据图块大小,CATiledLayer 甚至会更慢,因为它必须为一张图像绘制多个图块。
但是...
CATiledLayer 的要点是您不需要绘制所有图块,尤其是在放大非常非常大的图像时。知道实际需要哪些部分是明智的。它也很聪明地驱逐不再需要的瓷砖。
或者,要使此机制发挥作用,您需要分别提供图像的各个部分。我们谈论的是可能无法在未压缩的情况下保存在内存中的图像的总大小。
They might perform the same for small images because ghen the only difference in terms os performance is that CATiledLayer draws on a background thread. Depending on the tile size CATiledLayer would even be slower because it has to draw multiple tiles for one image.
BUT ...
the point of CATiledLayer is that you don't need to draw all tiles, especially when zooming into a very very large image. It is smart to know which parts are actually needed. It also is smart about evicting tiles that are not needed any more.
Or this mechanism to work you need to provide the individual parts of the image separately. We're talking a total size of an image that probably cannot be held in memory uncompressed.