1

我正在尝试将 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: 之后

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

4

2 回答 2

0

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

于 2010-02-07T10:10:15.277 回答
0

所以这个问题的答案原来是我自己的代码中的一个错误。

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

于 2010-02-18T07:17:22.050 回答