问题描述
我创建的应用程序有时会显示带有标签和文本框的叠加层。
I've created the app which sometimes shows up an overlay with label and textbox. It works nice, but I need it to work even with other apps are in full-screen mode and active.
对于overlay,我已经创建了自定义的窗口类并覆盖了它,但是我需要它来工作,甚至与其他应用程序在全屏模式和活动。 canBecomeKeyWindow
方法让无边框窗口成为关键窗口(只需返回 YES
)。
For overlay, I've create custom window class and overridden canBecomeKeyWindow
method to let borderless window become the key window (simply returns YES
).
所以它工作,但是当我运行eg Minecraft,然后使其全屏,我的覆盖可以覆盖它。但我不能在覆盖中输入NSTextField。如何解决?
So it works, but when I run e.g. Minecraft, and then make it full screen, my overlay can override it. But I can't type in NSTextField in the overlay. How to fix it?
我正在创建一个这样的叠加层:
I'm creating an overlay like this:
[[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。
But still, I can't seem to populate overlay's NSTextField with keyboard input.
推荐答案
尝试这个。为_fadedWindow创建子类。然后把它放在:
Try this. Create a subclass for _fadedWindow. Then put this in:
-(BOOL)canBecomeKeyWindow {
return YES;
}
这篇关于如何覆盖全屏幕游戏与键窗口无边框窗口(覆盖)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!