2012-11-16 104 views
2

我已經創建了應用程序,有時會顯示帶有標籤和文本框的疊加層。它工作的很好,但我需要它工作,即使其他應用程序處於全屏模式並處於活動狀態。如何使用keywindow無邊界窗口覆蓋全屏遊戲(覆蓋)?

對於覆蓋圖,我創建了自定義窗口類並覆蓋了canBecomeKeyWindow方法,讓無邊框窗口成爲關鍵窗口(僅返回YES)。

所以它的工作原理,但是當我運行例如我的世界,然後使其全屏,我的覆蓋可以覆蓋它。但是我無法在疊加層中輸入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用鍵盤輸入。

回答

2

試試這個。爲_fadedWindow創建一個子類。然後把它放在:

-(BOOL)canBecomeKeyWindow { 
    return YES; 
}