CATiledLayer changing images with different sizes when zooming (Map related :)
I have an UIScrollView with a UIView which in turn contains a CATiledLayer which displays a map.
I have to start with an overview where one can zoom in VERY deep. So I made 4 different images (actually PDFs) with 4 different sizes of the map (the largest has something like 5700 x 6700px)
I add the smallest (the overview) to the CATiledLayer and then swap the images on certain zoom levels.
So far, this kinda works.
The problem is, that when I display the largest map (closest zoom), the tiles get VERY big and it takes ages to draw them (and depending on the levels of detail/bias, the app produces a memory warning an crashes).
I tried to start with the largest map and set the zoom-level to the minimum when the map first shows, but then it takes ages to draw the overview because the tiles become very 开发者_高级运维small (when I don't set it the minimum-zoom, everything works smooth).
I tried to adjust the tile size when I switch the maps - but apparently, this doesn't work.
Any idea how I can solve this? ;)
Thanks for any help...
Edit:
I'm trying now to define two separate CATiledLayers and then swap them when a certain zoom-level is reached - but that makes the app crash?
[myContentView.layer replaceSublayer: tiledLayer with: tiledLayerBig];
oh my... :)
Edit2:
Ok - I got it working - more or less. The only thing that happens now is, that the CATiledLayer behaves strange when I add the largest image. It works fine for a while, but when a certain amount of tiles is drawn, I get a memory warning and the app crashes eventually. I actually would expect that the invisible tiles would get disposed when they leave the viewport. This doesn't seem to happen, so eventually, all the tiles will be drawn which seems to be too much for the iPhone-memory... :(
Any ideas, how to solve this?
It sounds like the tiles that are no longer being used are not being released from memory. What does your custom override's
- (void)drawRect:(CGRect)rect method
look like?
精彩评论