macos - DrawRect 和 NSProgressIndicator

标签 macos cocoa nsprogressindicator

我会很简短:

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

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

现在,由于循环需要很多秒,我正在尝试使用 NSProgresIndicator 来显示进度并在我使用dispatch_async和队列的循环中更新它。ProgressIndicator 更新,但没有绘制任何内容。如果不这样做不使用队列来绘制线条,但指标会在周期结束时更新。

我做错了什么?

错误:

<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.
<小时/>
// 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]

}
               });

最佳答案

一般来说,您不应该在后台线程或队列上绘图。

请阅读本文档以获取有关多线程绘图的信息。跳至“绘图限制”

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

关于macos - DrawRect 和 NSProgressIndicator,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23230577/

相关文章:

cocoa - 如何将 NSProgressIndicator 旋转 90 度

c - 如何在 Mac OS X 中获得与 Linux gcc/gnu crypt(3) 相同的 crypt(3) 函数? Linux gcc crypt(3) 有 MD5 和 SHA512。 Apple Gcc crypt(3) *仅* 使用 DES

macos - Mac QuickTime 组件调试

cocoa - 解析和更改 NSPredicate

objective-c - 一键执行多项操作

macos - 如何使用 Cocoa Bindings 使用 NSProgress 更新进度条?

macos - 如何以编程方式拦截 OSX (10.8) 打印命令?

macos - Mac 上的 Firefox 3.5 和 @font-face

cocoa - 为什么单元测试中的代码无法找到捆绑资源?

objective-c - 在 NSMenuItem 中使用 NSProgressIndicator