I'm trying to replicate the modal behavior of a sheet in Cocoa without actually using a sheet. That is, attaching a borderless child window to the main window and have the child window be the only responder. The parent window should remain key, support resizing, but cannot be navigated/responded to via keyboard or mouse.
我试图在没有实际使用工作表的情况下复制Cocoa中工作表的模态行为。也就是说,将无边框子窗口附加到主窗口并使子窗口成为唯一的响应者。父窗口应保持键,支持调整大小,但无法通过键盘或鼠标进行导航/响应。
So far I've added a borderless NSPanel subclass to the main window, which returns YES from -acceptsFirstResponder, and run the child window modally of the parent. The parent window remains the key window (as the NSPanel subclass returns NO from -canBecomeKeyWindow) but the parent window still has focus. I can use the keyboard to selected a button, which does nothing because of the modal child window. I need the child window to become first responder and calling -makeFirstResponder and setting the -initialFirstResponder view for the window has not effect.
到目前为止,我已经在主窗口中添加了一个无边界的NSPanel子类,它从-acceptsFirstResponder返回YES,并以模态方式运行父窗口的子窗口。父窗口仍然是关键窗口(因为NSPanel子类从-canBecomeKeyWindow返回NO),但父窗口仍然具有焦点。我可以使用键盘选择一个按钮,由于模态子窗口,该按钮无效。我需要子窗口成为第一响应者并调用-makeFirstResponder并为窗口设置-initialFirstResponder视图无效。
1 个解决方案
#1
1
NSWindow
has had an - (void)addChildWindow:(NSWindow *)childWindow ordered:(NSWindowOrderingMode)orderingMode
method since Mac OS X 10.2. Using the NSWindowAbove
ordering mode should be pretty close to what you're looking for. If you create the child window to cover the parent (make the child window borderless), but leave the parent's titlebar exposed – that should do what you're looking for. You may still need to disable interaction with the controls on the parent window while the child is shown if that's the behaviour you want.
NSWindow有一个 - (void)addChildWindow :( NSWindow *)childWindow命令:(NSWindowOrderingMode)来自Mac OS X 10.2的orderingMode方法。使用NSWindowAbove订购模式应该非常接近您正在寻找的。如果您创建子窗口以覆盖父窗口(使子窗口无边界),但保留父窗口的标题栏 - 这应该是您正在寻找的。您可能仍需要在显示子窗口时禁用与父窗口上的控件的交互,如果这是您想要的行为。
#1
1
NSWindow
has had an - (void)addChildWindow:(NSWindow *)childWindow ordered:(NSWindowOrderingMode)orderingMode
method since Mac OS X 10.2. Using the NSWindowAbove
ordering mode should be pretty close to what you're looking for. If you create the child window to cover the parent (make the child window borderless), but leave the parent's titlebar exposed – that should do what you're looking for. You may still need to disable interaction with the controls on the parent window while the child is shown if that's the behaviour you want.
NSWindow有一个 - (void)addChildWindow :( NSWindow *)childWindow命令:(NSWindowOrderingMode)来自Mac OS X 10.2的orderingMode方法。使用NSWindowAbove订购模式应该非常接近您正在寻找的。如果您创建子窗口以覆盖父窗口(使子窗口无边界),但保留父窗口的标题栏 - 这应该是您正在寻找的。您可能仍需要在显示子窗口时禁用与父窗口上的控件的交互,如果这是您想要的行为。