我正在尝试勾勒出一个类似于 Mission Control 和 Exposé 的窗口。我创建了一个透明的自定义 NSWindow
,其轮廓类似于 this question ,但我根本不希望用户与此窗口交互。
有什么办法可以做到这一点吗?
下面是我的自定义 NSWindow,我一直在调用它
windowOutline = [[WindowOutline alloc] initWithContentRect:rect styleMask:1 backing:NSBackingStoreBuffered defer:false];
[windowOutline makeKeyAndOrderFront:self];
[windowOutline drawRect:rect];
<小时/>
- (id)initWithContentRect:(NSRect)contentRect
styleMask:(NSUInteger)windowStyle
backing:(NSBackingStoreType)bufferingType
defer:(BOOL)flag
{
self = [super
initWithContentRect:contentRect
styleMask:NSBorderlessWindowMask
backing:bufferingType
defer:flag];
if (self)
{
[self setOpaque:NO];
[self setBackgroundColor:[NSColor clearColor]];
}
return self;
}
- (void)drawRect:(NSRect)frame {
frame = NSInsetRect(self.frame, 3.0, 3.0);
[NSBezierPath setDefaultLineWidth:6.0];
NSBezierPath *path = [NSBezierPath bezierPathWithRoundedRect:frame
xRadius:6.0 yRadius:6.0];
[[NSColor redColor] set];
[path stroke];
}
最佳答案
你已经成功了一半。您需要按照in the answer you've already found所述创建自定义窗口和内容 View 。 。请注意,drawRect:
位于自定义 View 中(您将其设置为窗口的 contentView
),而不位于您的窗口子类中。从您的代码片段来看,尚不完全清楚您是否已这样设置。您现在应该有一个透明的轮廓窗口。
然后您需要:
- 设置窗口级别
-[NSWindow setLevel:]
上面的常量之一NSNormalWindowLevel
。 - 通过在 Info.plist 中设置
LSUIElement
,使您的应用程序成为代理应用程序,这样它就不会出现在 Dock 等中。 - 将窗口上的
ignoresMouseEvents
设置为YES
。
关于objective-c - 概述系统窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15076262/