I am working on an application where I render PDF content in a CATiledLayer. I want to trigger one method after the rendering of the tiled layer is complete.
我正在开发一个应用程序,我在CATiledLayer中呈现PDF内容。我想在完成平铺图层的渲染后触发一个方法。
Is there any delegate method that will be called immediately after the rendering of all visible tiles is completed? Is there any other way of knowing when this is finished?
在完成所有可见切片的渲染后,是否会立即调用任何委托方法?有没有其他方法可以知道何时完成?
2 个解决方案
#1
3
You can calculate the number of tiles your drawing requires before it's drawn. In drawRect of the tilingview, each tile is drawn only ONCE. So put a counter in part of the draw rect that calls a new tile. When your counter reaches the total number, call your method.
您可以在绘制之前计算绘图所需的拼贴数。在tilingview的drawRect中,每个图块仅绘制一次。因此,将一个计数器放在调用新tile的draw rect的一部分中。当您的计数器达到总数时,请调用您的方法。
Keep in mind that drawrect for tiling is done on a background thread.
请记住,平铺的绘制是在后台线程上完成的。
#2
0
This requires some creative thinking. I've had a similar problem where I've needed to abort the rendering of a tiled layer mid-cycle. The way I worked round it is somewhat complex, but seems to work reasonably well. It involves wrapping the draw calls to the tiled layer inside a NSThread
. Threads have a isFinished
bool that you can key-value observe to discover when a tiled layer has completed its render.
这需要一些创造性思维。我有一个类似的问题,我需要中止循环中间平铺图层的渲染。我处理它的方式有点复杂,但似乎工作得相当好。它涉及将绘制调用包装到NSThread内的平铺层。线程有一个isFinished bool,您可以键值观察以发现平铺图层何时完成其渲染。
If you're not comfortable with threading on iOS this may be more trouble than its worth, but will give you the advantage of knowing when the rendering has finished, and also being able to cancel the thread operation (and thus the render) if required.
如果你对iOS上的线程感觉不舒服,这可能比它的价值更麻烦,但是会让你知道渲染何时完成,并且还能够在需要时取消线程操作(以及渲染) 。
#1
3
You can calculate the number of tiles your drawing requires before it's drawn. In drawRect of the tilingview, each tile is drawn only ONCE. So put a counter in part of the draw rect that calls a new tile. When your counter reaches the total number, call your method.
您可以在绘制之前计算绘图所需的拼贴数。在tilingview的drawRect中,每个图块仅绘制一次。因此,将一个计数器放在调用新tile的draw rect的一部分中。当您的计数器达到总数时,请调用您的方法。
Keep in mind that drawrect for tiling is done on a background thread.
请记住,平铺的绘制是在后台线程上完成的。
#2
0
This requires some creative thinking. I've had a similar problem where I've needed to abort the rendering of a tiled layer mid-cycle. The way I worked round it is somewhat complex, but seems to work reasonably well. It involves wrapping the draw calls to the tiled layer inside a NSThread
. Threads have a isFinished
bool that you can key-value observe to discover when a tiled layer has completed its render.
这需要一些创造性思维。我有一个类似的问题,我需要中止循环中间平铺图层的渲染。我处理它的方式有点复杂,但似乎工作得相当好。它涉及将绘制调用包装到NSThread内的平铺层。线程有一个isFinished bool,您可以键值观察以发现平铺图层何时完成其渲染。
If you're not comfortable with threading on iOS this may be more trouble than its worth, but will give you the advantage of knowing when the rendering has finished, and also being able to cancel the thread operation (and thus the render) if required.
如果你对iOS上的线程感觉不舒服,这可能比它的价值更麻烦,但是会让你知道渲染何时完成,并且还能够在需要时取消线程操作(以及渲染) 。