1

I have extracted some code from the PhotoScroller sample code from Apple to use the CATiledLayer. I have an image of 8000x7000px loaded from internet, in tiles.

This is kind of a map-function in my app. I also have two almost identical images, with different overlays (tried to only add the overlay without luck).

I have an UISegmentedControl to toggle between the three choices, and I want the imageView to load the images from the selected image. So if the user zoomes in on one of the images, and selects another option, then the scale and coordinated stays the same, and the imageView loads the chosen image in the necessary tile-spots.

I have partially managed this. Or, I have actually managed this, but when I select another option, the whole screen goes black when the function [imageView removeFromSuperview]; is called. After being black in a couple of seconds(depending on internet speed) it shows the correct tiles.

I want the layer to "fade" over to the next layer if possible. As you maybe know, when using CATiledLayer, the first layer is the whole image in low resolution, but when zooming in, the necessary tiles "fade" in to the next layer with smaller tiles.

I basically need to give the (TilingView*)imageView a "reload"-command, and want it to "fade" over the last image.

I tried to comment out the [imageView removeFromSuperview];, and that actually got me close to what I want. When I zoomed in, and selected another option, the new image actually faded over the old one, however, when I zoomed back out, the old image was clearly sticking around in the background(behind the new image), not responding to anything. I need to remove it from the superView at a later point, but I have no longer access to it as the new image has taken its place as imageView. I know people might want to see code here, but I have really no idea what code to show.. And the CATiledLayer is SO POORLY documented I am really having a hard time understanding what's going on.

Stunner
  • 12,025
  • 12
  • 86
  • 145
Sti
  • 8,275
  • 9
  • 62
  • 124
  • If you're loading full tiles instead of jpegs from the inet, that would seem to take more time. You might want to check out PhotoScrollerNetwork (on github) - it lets you download jpegs, it tiles them for you, and allows concurrent downloads. You can also use it with Quartz only or libjpegturbo. – David H Aug 26 '12 at 15:03
  • @DavidH Yeah, I checked in on that, but wouldn't that take more time? I guess the whole image has to be downloaded for the imageview to show anything? Instead of just the required tile? As this is a map-function, users will probably never view the whole in-depth layer of all images, and therefore not needing the whole images downloaded.. – Sti Aug 26 '12 at 16:03
  • You are correct if you can download tiles of just the first small view first it's a huge win in terms of time. – David H Aug 26 '12 at 16:59
  • 1
    Actually you just gave me a great idea on how to speed up PSN - use progressive jpegs. This would allow a small image to appear real quick. Instead of working larger to smaller do the reverse! Thanks! – David H Aug 26 '12 at 17:11

1 Answers1

1

I made it work through some sketchy code. There probably are other better solutions, but this is the only one I know of at the moment.

The problem was that when I removed [imageView removeFromSuperview];, it did not unload the last image, thus letting it be in the memory forever. As it was not affected by zooming and scrolling, when I zoomed out, it was always there in the background. If I was to switch between options multiple times, multiple images would add up in the background.

I simply created a "helper" as I call it. A new imageView, which gets the content of the old imageView when switching option, without removing it from the superview just yet, as a premature removal results in black screen when the new image hasn't loaded quite yet.

I now call the [helper removeFromSuperview]; in the delegate methods scrollViewWillBeginZooming AND in scrollViewWillBeginDragging. This results in memory containing at the most two images in the time between clicking the other option, and user scrolls or zoomes.

Note: If the user scrolls or zoomes immediately after switching option in the UISegmentedControl, it turns black because the new image hasn't been loaded yet.

Sti
  • 8,275
  • 9
  • 62
  • 124