首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >DrawRect和NSProgressIndicator

DrawRect和NSProgressIndicator
EN

Stack Overflow用户
提问于 2014-04-22 21:29:57
回答 1查看 193关注 0票数 0

我将非常简短:

我正在用drawrect和NSBezierPath绘制线条。

为了绘制这些线,我使用了for循环。

现在,由于循环需要很多秒,所以我尝试使用NSProgresIndicator来显示进度,并在我使用dispatch_async &queue的循环中更新它。ProgressIndicator更新,但没有绘制任何内容。如果不使用队列,则绘制行,但指示符在周期结束时更新。

我做错什么了?

错误:

代码语言:javascript
复制
<Error>: CGContextRestoreGState: invalid context 0x0. 
This is a serious error. 
This application, or a library it uses, is using an invalid context
and is thereby 
contributing to an overall degradation of system stability and reliability.
 This notice is a courtesy: please fix this problem.
 It will become a fatal error in an upcoming update.

代码语言:javascript
复制
// SAMPLE OF CODE
dispatch_queue_t myQueue = dispatch_queue_create("my queue", NULL);
dispatch_async(myQueue, ^
               {
for (int i = 1; i <= 200; i++) {

    dispatch_async(dispatch_get_main_queue(), ^{
        [istance set_progress:i]; 
//This sets the progress, but bezierPath doesn't work
    });


//Bezier already alloc & init
[my_path moveToPoint....]
[my_path lineToPoint....]
[my_path stroke]

}
               });
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-25 20:58:43

通常,您不应该在后台线程或队列上绘图。

有关多线程绘图的信息,请阅读此文档。跳到“绘图限制”

https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/Multithreading/ThreadSafetySummary/ThreadSafetySummary.html

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23230577

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档