作者:依然-狠幸福 | 来源:互联网 | 2023-05-19 04:56
WhentryingtodrawjustlikeinaniOSapplicationwefacedaproblem.Afterhoursofsearchwithn
When trying to draw just like in an iOS application we faced a problem. After hours of search with no luck, we decided to ask here.
当我们试图像在iOS应用程序中那样绘制时,我们遇到了一个问题。经过几个小时的搜寻,运气不好,我们决定在这里问一下。
To make a drawing we created a class as
为了绘制一个图,我们创建了一个类。
import Cocoa
class DrawImageHolder: NSView {
override func drawRect(dirtyRect: NSRect) {
super.drawRect(dirtyRect)
print(" drawRect is executed ")
// drawing code
}
}
then we connected the class to a NSView
like this
然后我们将类连接到NSView
But we have received
但是我们已经收到
-[NSApplication runModalForWindow:] may not be invoked inside of transaction commit (usually this means it was invoked inside of a view's -drawRect: method.) The modal dialog has been suppressed to avoid deadlock.
-[NSApplication runModalForWindow:]不能在事务提交内部调用(通常这意味着它在视图的- drawrect:方法内部调用)。模态对话框已被抑制以避免死锁。
message from console instead of drawing.
来自控制台的消息,而不是绘图。
Besides the print(" drawRect is executed ") was not executed.
此外,打印(“drawRect被执行”)没有被执行。
Most probably we are forgetting something simple.
很可能我们忘记了一些简单的事情。
1 个解决方案