大家好:
如果我在控制器的视图中创建NSTextField,那么一切都很好 - 字段是可编辑的。 不幸的是,我必须在新的自定义NSWindow中创建NSTextField。我的代码如下所示,产生的字段看起来没有聚焦(文本选择是灰色的)并且无法编辑(没有光标和键盘输入反应)。我可以用鼠标改变文本选择,但只有这些。
我需要启用NSWindow以接收键盘输入吗?
感谢您的帮助, --Josef
NSRect windowRect = [[self.window contentView] frame] ;
NSWindow* uiWindow = [[NSWindow alloc] initWithContentRect:windowRect
styleMask:NSBorderlessWindowMask
backing:NSBackingStoreBuffered defer:YES];
[uiWindow setBackgroundColor: [NSColor redColor/*clearColor*/]];
[uiWindow setOpaque:NO];
NSView* uiView = [[[NSView alloc] initWithFrame:NSMakeRect(0, 0, windowRect.size.width, windowRect.size.height)] autorelease];
[uiView translateOriginToPoint:NSMakePoint(100, uiView.bounds.size.height/2)];
uiView.wantsLayer = YES;
[uiWindow setContentView:uiView];
NSTextField *textField;
textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 800, 80)];
[textField setFont:[NSFont fontWithName:@"Helvetica Bold" size:60]];
[textField setStringValue:@"My Label"];
[textField setBezeled:YES];
[textField setDrawsBackground:YES];
[textField setEditable:YES];
[textField setSelectable:YES];
[textField setEnabled:YES];
[uiView addSubview:textField];
// THIS DOES NOT WORK
[self.window addChildWindow:uiWindow ordered:NSWindowAbove];
// THIS WORKS
//[_graphicView addSubview:uiView];