我创建的应用程序有时会显示带有标签和文本框的叠加层。它工作得很好,但我需要它即使在其他应用程序处于全屏模式且处于活动状态时也能工作。
对于覆盖,我创建了自定义窗口类并覆盖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 。
尝试这个。为 _fadedWindow 创建一个子类。然后将其放入:
-(BOOL)canBecomeKeyWindow {
return YES;
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)