iphonecalayerpdf-rendering

Stopping updation of CALayer's contents in iPhone


I am working on a pdf Reader application.I am making use of CALayer to render the pdf contents.i employed swipe gesture to navigate across the pages.The issue is, if the user attempts to go to next or previous page once the rendering of layer has started,the 'going to next page' action is being performed after completion of rendering of the current pdf page on to the layer.I want the rendering of the current page to be stopped immediately as soon as the swipe occurred and next page should start rendering on the layer.any idea please help.

UPDate: here is my code

-(void)loadSinglePageWithWidth:(float)width andHeight:(float)height{
    draw=0;
    NSLog(@"before draw");
    [markupView.layer insertSublayer:renderingLayer1 above:tiledLayer1];
    loadingThread=[[NSThread alloc] initWithTarget:self selector:@selector(loadSinglePage) object:nil];
    [loadingThread start];
}
-(void)loadSinglePage{
    [renderingLayer1 setNeedsDisplay];
}

as soon as i swipe, in my action method, the code is written like

[loadingThread cancel];
[loadingThread release];
loadingThread=nil;

even i cancel the "loadingThread" the execution of the drawLayer: method seems to be running.am i correct with this thread approach?will drawLayer: code be executed by the thread which i am using to call setNeedsDisplay method?


Solution

  • I think that the best solution is to do the rendering in a separate thread. Once it's done, you simply display the rendered image on the screen. If not, you can always cancel the operation.