How does CATiledLayer know when to provide a new tile?
Because of various reasons, I am considering to make my own implementation of CATiledLayer. I have done some investigation, but I don't seem to be able to figure out how CATiledLayer knows which tile to provide. For example, when you scroll t开发者_JAVA百科he layer, setPosition: or setBounds: are never called. It looks like the background thread just calls drawLayer:inContext: of the delegate out of the blue without any triggers. I have found out that CATiledLayer calls setContent: with an instance of "CAImageProvider", and the all calls to drawLayer:inContext: originate from that class. So probably that one is the key in determining what tile to draw. But I cannot find any documentation on that class.
So... does anybody know how this is working, and how I might be able to override it?
As for the disadvantages of CATiledLayer:
- it always uses screen resolution (or x2, x4, etc); you cannot set it to the native resolution of your source images
- you cannot specify any other scaling factor than 2
- you have to specify the levelsOfDetail and levelsOfDetailBias, for which I see no implementation reason at all. If you have content that is infinitely scalable, like fractals, then this is very limiting.
- most importantly: if you restrict it to zooming in only one direction (I do that by forcing the scale factor of one direction to 1 in setTransform:), it acts all weird
In drawLayer:inContext:
, you can get the bounding box using CGContextGetClipBoundingBox
. CGContextGetCTM
should give you information about the current resolution.
精彩评论