无边界的孩子NSWindow没有得到事件

时间:2011-10-05 19:39:29

标签: cocoa nswindow

我使用此代码创建了一个NSWindow,但我没有收到任何鼠标或键盘事件:

window = [[OverlayWindow alloc] initWithContentRect:bounds styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO];
[parentWindow addChildWindow:window ordered:NSWindowAbove];
NSView * rootView = [[OverlayView alloc] init];
[window setOpaque:NO];
[window setBackgroundColor:[NSColor clearColor]];
[window setContentView:rootView];
[window setIgnoresMouseEvents:NO];
[self reshapeToRect:bounds];

并在OverlayWindow中:

- (BOOL) canBecomeKeyWindow { return YES; }
- (BOOL) canBecomeMainWindow { return YES; }
- (BOOL) acceptsFirstResponder { return YES; }
- (BOOL) becomeFirstResponder { return YES; }
- (BOOL) resignFirstResponder { return YES; }

1 个答案:

答案 0 :(得分:3)

[window orderWindow:NSWindowAbove relativeTo:[parentWindow windowNumber]];

做了这个伎俩