2013-02-25 91 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