gpt4 book ai didi

macos - DrawRect 和 NSProgressIndicator

转载 作者:行者123 更新时间:2023-12-03 17:52:11 26 4
gpt4 key购买 nike

我会很简短:

我正在使用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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com