【发布时间】:2013-03-02 11:24:56
【问题描述】:
我创建的应用程序有时会显示带有标签和文本框的叠加层。它很好用,但即使其他应用程序处于全屏模式并处于活动状态,我也需要它才能工作。
对于覆盖,我创建了自定义窗口类并重写了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。
【问题讨论】:
标签: objective-c xcode macos cocoa