2013-02-25 92 views
0

我想勾画出一个类似于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]; 
} 
+0

你试过了什么?你可能会发布一些代码来陪伴你的描述吗? – Jules 2013-02-25 21:14:02

+0

那里。添加它。 – agg23 2013-02-25 21:30:36

回答

1

你已经走了一半。您需要按in the answer you've already found所述创建自定义窗口和内容视图。请注意,drawRect:位于您的窗口子类中的自定义视图中(您将设置为窗口的contentView),而不是。从你的代码片段中可以看出,如果你已经设置好了,那还不完全清楚。你现在应该有一个透明的,概括的窗口。

然后你需要:常量的上述NSNormalWindowLevel

  1. 设置窗口的水平-[NSWindow setLevel:]之一。
  2. 通过在Info.plist中设置LSUIElement,使您的应用程序成为代理应用程序,以便它不会出现在Dock等中。
  3. 在窗口上设置ignoresMouseEventsYES
+0

完美的工作。非常感谢你! – agg23 2013-02-25 23:34:13