我想將NSTrackingArea安裝到全屏視圖中以獲取鼠標移動事件。NSTrackingArea with fullscreen window/view
但是,每當我這樣做,我得到一個斷言錯誤。我搜索了網頁,但一直未能找到任何線索。
*** 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:
任何人有什麼想法?這是不是我應該採取的方法來獲取全屏窗口中的鼠標移動事件?
這些方法已實現,但在窗口全屏顯示時不會被調用。 – wadesworld 2010-02-08 04:22:53
有一個示例應用程序,您可以看看:http://developer.apple.com/mac/library/samplecode/GeekGameBoard/index.html(它使用NSView子類而不是OpenGL)。 – 2010-02-08 09:30:45
如果您想使用'-mouseMoved:',請確保您調用'[[glView窗口] setAcceptsMouseMovedEvents:YES]'。 – 2010-02-09 01:02:32