Child window is what you need.
Create NSWindow
with NSBorderlessWindowMask
and define it to be transparent using - setOpaque:
and - setBackgroundColor:
methods. Then add newly created window as a child of window containing an instance of NSWebView
(using NSWindow
's - addChildWindow:ordered:
method). Moving parent window will automatically cause child window to move.
Update with working code:
CGRect wRect = self.window.frame;
NSView *contentView =self.window.contentView;
CGRect cRect = contentView.frame;
CGRect rect = CGRectMake(wRect.origin.x, wRect.origin.y, cRect.size.width, cRect.size.height);
NSWindow *overlayWindow = [[NSWindow alloc]initWithContentRect:rect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered
defer:NO];
overlayWindow.backgroundColor = [NSColor redColor];
[overlayWindow setOpaque:NO];
overlayWindow.alphaValue = 0.5f;
[self.window addChildWindow:overlayWindow ordered:NSWindowAbove];
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…