I came up with a very neat and nice solution (custom TiledLayer implementation):
I don't use CATiledLayer as contentView of the scrollView anymore. Instead I added a CALayer subclass to it and added my tiles to it as sublayers. Each tile contains the tile bitmap as contents. When zooming in with the scrollview I switch tiles manually based on the current zoomlevel. Thats perfect!!!
If somebody wants to know details of the implementation -> no problem, write a comment and I post it here.
EDIT:
Details about the implementation:
The implementation in fact is really easy:
- Add a UIScrollView to your View/Controller View
- Add a UIView (from now on referred to as
tileView
) as contentView to the ScrollView - same size as ScrollView size (this is completely zoomed out mode - factor 1) - Activate zooming (I had minimum zoom factor 1 and max. 9)
- When you now place an image into the
tileView
, zooming into level 9 will give as a very unsharp pixelated image - that's what we want (I'll explain why) - If you like crisp clear images when you zoom in, you should add CALayer instances (
tiles
) withaddSublayer:
totileView
- Assuming you have a zoomFactor of 3 (I had - meaning 1 Tile in layer 0 - zoomFactor 1 will consist of 3x3 = 9 tiles in layer 1 - zoomFactor 3)
- In layer 0 say you put 3x4 tiles with 243x243 (3 times devidable by 3) pixels (as sublayers to
tileView
). You put your same size tile images asCALayer contents
. Zooming to zoomFactor 3 makes them blurry (like old google maps) - When you hit zoomFactor 3 remove all 12 layers from superlayer and replace them with 3 times smaller ones (81x81 pixels). You get 9 times more layers in a whole.
- Now that you have 3 times smaller tile layers, the trick is the
.contents
property ofCALayer
. Even if the layer is 81x81, the contents (your image) are still full resolution, meaning if you put a 243x243 pixels image as contents of your 81x81 pixels CALayer tile, on zoomFactor 3 it looks like a 243x243 pixels tile!!!
- In layer 0 say you put 3x4 tiles with 243x243 (3 times devidable by 3) pixels (as sublayers to
You can go with that on any zoomFactor (3,9,12) deeper. The tiles get smaller and smaller, but setting the original image as contents, the tile will look crisp and sharp at the exact zoomFactor they are placed in.
If you like your tiles look sharp even between the zoomFactors, you have to set a 3 times taller image as .contents
. Then your tile is crisp and sharp even short before you're passing the next zoomLevel.
The one thing you have to figure out is, removing all tiles on a layer when passing the zoomLevel factor is not efficient. You only have to update the visible tiles in rect.
Not the nicest of all solutions, but it works and if someone does a well designed library maybe there is potential for this to be a clean solution.