我创建的应用有时会显示带有标签和文本框的叠加层。它工作得很好,但我需要它才能工作,即使其他应用程序处于全屏模式并且处于活动状态。
对于叠加,我创建自定义窗口类并重写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];
但是,我似乎无法用键盘输入填充overlay的NSTextField。
答案 0 :(得分:2)
试试这个。为_fadedWindow创建一个子类。然后将其放入:
-(BOOL)canBecomeKeyWindow {
return YES;
}