objective-c - 概述系统窗口

标签 objective-c xcode cocoa nswindow

我正在尝试勾勒出一个类似于 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),而不位于您的窗口子类中。从您的代码片段来看,尚不完全清楚您是否已这样设置。您现在应该有一个透明的轮廓窗口。

然后您需要:

  1. 设置窗口级别-[NSWindow setLevel:]上面的常量之一NSNormalWindowLevel
  2. 通过在 Info.plist 中设置 LSUIElement,使您的应用程序成为代理应用程序,这样它就不会出现在 Dock 等中。
  3. 将窗口上的 ignoresMouseEvents 设置为 YES

关于objective-c - 概述系统窗口,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15076262/

相关文章:

iphone - 如何自定义 iOS 警报 View ?

iphone - 雪豹和 XCode 3.1

xcode - 连接不可用 - Lion OSX 升级后出现 Xcode 错误

iphone - 在启动前添加屏幕

iphone - 在 Cocoa 中使用/存储 float 组

iphone - 针对 iOS 3 和 iOS 4 启用了 locationServices

ios - iOS UITableView 中的下拉列表

Objective-C 快速枚举搜索不会中断

ios - AppDelegate 类不适用于 iOS Swift 应用程序中的 Obj-C 嵌入式库

cocoa - 我可以使用窗口内的对象来移动窗口吗?