我正在尝试将 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: 之后
有人有什么想法吗?这不是我应该在全屏窗口中获取鼠标移动事件的方法吗?