オーバーレイウィンドウを作成するには、NSWindowをサブクラス化し、そのスタイルマスクと背景色を設定する必要があります。
@implementation BigTransparentWindow
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)windowStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)deferCreation
{
self = [super initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask //this makes the window transparent
backing:bufferingType
defer:deferCreation];
if(self)
{
[self setOpaque:NO];
[self setHasShadow:NO];
[self setBackgroundColor:[[NSColor blackColor] colorWithAlphaComponent:0.5]];
}
return self;
}
@end
次に、すべての画面をカバーするようにウィンドウのフレームを設定する必要があります。また、ウィンドウレベルを適切に設定する必要があります。
- (IBAction)showWindow:(id)sender
{
//set the window so it covers all available screens
NSRect screensRect = NSZeroRect;
for(NSScreen* screen in [NSScreen screens])
{
screensRect = NSUnionRect(screensRect,[screen frame]);
}
[yourWindow setFrame:screensRect display:YES];
if(coverScreen)
{
//set the window so it is above all other windows
[yourWindow setLevel:kCGMaximumWindowLevel];
}
else
{
//set the window so it sits just above the desktop icons
[yourWindow setLevel:kCGDesktopIconWindowLevel + 1];
}
}
すでに述べたように、のNSApplicationPresentationOptions
設定を使用しNSApp
て、ユーザーがシステムを操作する方法を制御できます。ロックアウトせずにこれをテストする簡単な方法はNSTimer
、タイムアウト期間後にアプリをキオスクモードから引き出すメソッドを呼び出すを設定することです。