同步调用 NSWindow makeKeyAndOrderFront
我正在为 Mac OS 编写一个小型 Cocoa 应用程序,我的目标是显示一个窗口,然后读取屏幕上的像素。我已经知道如何执行后一部分,但在继续之前无法显示窗口。据我所知,像 NSWindow 的 makeKeyAndOrderFront 触发的窗口更新会被推迟。
我对 Cocoa 还比较陌生,但我基本上想做这样的事情:
[myWindow makeKeyAndOrderFront:self];
// application blocks right here until the window is actually shown
...
那么我如何使阻塞操作发生呢?
I am writing a small Cocoa application for Mac OS, and my goal is to show a window, and then read the pixels on the screen. I already know how to do the latter part, but am having trouble with having the window show up before proceeding. From what I've seen, window updates like the ones triggered by NSWindow's makeKeyAndOrderFront are deferred.
I'm still relatively new to Cocoa, but I basically want to do something like this:
[myWindow makeKeyAndOrderFront:self];
// application blocks right here until the window is actually shown
...
So how do I make that blocking operation happen?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
也许您可以从窗口而不是屏幕获取像素?在 Mac OS X 上,(几乎)每个窗口都有自己的缓冲区(后备存储),无论它是否可见。即使系统对话框遮挡了窗口所在的屏幕区域,这也将确保您的测试能够正常工作。
Perhaps you could obtain the pixels from the window, rather than the screen? On Mac OS X, (nearly) every window has its own buffer (backing store), whether or not it is visible. This will also ensure your test works even if there is a system dialog obscuring the area of the screen where the window is placed.
尝试在窗口上调用 -[NSWindow display],这将强制它立即显示。
Try calling -[NSWindow display] on your window, that will force it to display immediately.
只需将一个对象委托为窗口的
NSWindowDelegate
并在委托中调用windowDidBecomeKey:
后即可截取屏幕截图。Simply delegate an object as the window's
NSWindowDelegate
and take your screenshot oncewindowDidBecomeKey:
is called in the delegate.