CATiledLayer and UIImageView what's the big deal between them?

932 views Asked by At


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:

  1. -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
  2. -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
  3. -If I send memory warning nothing change between the two solution(only on sim)
  4. -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.

1

There are 1 answers

1
Cocoanetics On BEST ANSWER

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.