NSTrackingArea具有全屏窗口/视图

时间:2010-02-07 01:55:22

标签: cocoa core-graphics nsview

我正在尝试将NSTrackingArea安装到全屏视图中,以便获取鼠标移动事件。

然而,每当我这样做时,我都会收到断言错误。我在网上搜索过,但一直找不到任何线索。

*** Assertion failure in -[_NSFullScreenWindow _setTrackingRect:inside:owner:userData:useTrackingNum:install:], /SourceCache/AppKit/AppKit-1038.25/AppKit.subproj/NSWindow.m:3944

以下是设置跟踪区域的代码(x = 1024,y = 768):

    cocoaWindow = [[NSWindow alloc] initWithContentRect:NSMakeRect(0.0, 0.0, x,y)
                                              styleMask: NSTitledWindowMask
                                                backing: NSBackingStoreBuffered
                                                  defer:NO];
    glView = [[WLMacGLView alloc] initWithFrame:NSMakeRect(0.0, 0.0,  x,y) pixelFormat:[WLMacGLView defaultPixelFormat]];
    [glView setCocoaController:self];

    //add the glView as a subview of the window's content view
    [[cocoaWindow contentView] addSubview:glView];
    NSRect r = [glView frame];
    NSTrackingArea *track = [[NSTrackingArea alloc] initWithRect:r options: NSTrackingMouseMoved | NSTrackingActiveWhenFirstResponder | NSTrackingActiveInKeyWindow
                                   owner:self userInfo:nil];
    [glView addTrackingArea:track];
    [glView enterFullScreenMode:[NSScreen mainScreen] withOptions:nil];
    [glView createContext];

断言发生在调用enterFullScreenMode:withOptions:

之后

有人有任何想法吗?这不是我应该采取的方法来在全屏窗口中获取鼠标移动事件吗?

2 个答案:

答案 0 :(得分:0)

如果您想在整个视图中跟踪鼠标,我认为更容易实现mouseDown:mouseMoved:mouseUp:方法以获取鼠标事件。< / p>

答案 1 :(得分:0)

所以这个问题的答案结果证明是我自己代码中的错误。

初始化NSTrackingArea时,我向所有者传递了错误的对象。通过的正确方法是NSView。经过更正后,所有工作都按预期进行。

相关问题