停止更新 iPhone 中的 CALayer 内容
我正在开发一个 pdf 阅读器应用程序。我正在使用 CALayer 来渲染 pdf 内容。我使用滑动手势来浏览页面。问题是,如果用户在渲染后尝试转到下一页或上一页图层已启动,当前 pdf 页面渲染到该图层完成后正在执行“转到下一页”操作。我希望在发生滑动和下一页时立即停止当前页面的渲染应该开始在图层上渲染。任何想法请帮忙。
更新日期: 这是我
-(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];
}
一滑动的代码,在我的操作方法中,代码的编写就像
[loadingThread cancel];
[loadingThread release];
loadingThread=nil;
我取消“loadingThread”一样,drawLayer的执行:方法似乎正在运行。我对这种线程方法是否正确?将drawLayer:代码由我用来调用 setNeedsDisplay 方法的线程执行?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为最好的解决方案是在单独的线程中进行渲染。完成后,您只需在屏幕上显示渲染的图像即可。如果没有,您可以随时取消该操作。
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.