2

我创建了有时会显示带有标签和文本框的叠加层的应用程序。它工作得很好,但即使其他应用程序处于全屏模式并处于活动状态,我也需要它才能工作。

对于叠加,我创建了自定义窗口类和重写canBecomeKeyWindow方法,让无边框窗口成为关键窗口(只需返回YES)。

所以它可以工作,但是当我运行例如 Minecraft,然后使其全屏显示时,我的叠加层可以覆盖它。但我无法在叠加层中输入 NSTextField。如何解决?

我正在创建这样的叠加层:

[[NSWorkspace sharedWorkspace] hideOtherApplications];
NSRect frame = [[NSScreen mainScreen] frame];
_fadedWindow = [[CustonWindow alloc] initWithContentRect:frame
                                           styleMask:NSBorderlessWindowMask
                                             backing:NSBackingStoreBuffered
                                            defer:NO];
[_fadedWindow setAcceptsMouseMovedEvents:YES];
[_fadedWindow setOpaque:NO];
[_fadedWindow setLevel:CGShieldingWindowLevel()];
[_fadedWindow setBackgroundColor:[NSColor colorWithDeviceRed:0.0 green:0.0 blue:0.0 alpha:0.8]];
NSApplicationPresentationOptions options = NSApplicationPresentationDisableProcessSwitching + NSApplicationPresentationHideDock + NSApplicationPresentationDisableForceQuit + NSApplicationPresentationDisableSessionTermination + NSApplicationPresentationDisableHideApplication;
[NSApp setPresentationOptions:options];
_fadedWindow.alphaValue = 0;
[_fadedWindow orderFrontRegardless];
[[_fadedWindow animator] setAlphaValue:1];
[_fadedWindow toggleFullScreen:self];
[_fadedWindow makeKeyAndOrderFront:self];
[NSApp activateIgnoringOtherApps:YES];
[_fadedWindow orderFront:self];

但是,我似乎无法用键盘输入填充覆盖的 NSTextField 。

4

1 回答 1

2

试试这个。为 _fadedWindow 创建一个子类。然后把这个放进去:

-(BOOL)canBecomeKeyWindow {
    return YES;
}
于 2013-03-02T03:24:56.757 回答