Cocos2d项目中Mac上的可编辑NSTextField

时间:2012-02-26 14:40:50

标签: objective-c macos cocoa cocos2d-iphone

我正在尝试在Cocos2d项目中在Mac上显示可编辑的NSTextField。我直接从AppDelegate运行我的所有测试代码,使测试变得简单并消除所有副作用。下面的代码显示了具有良好编辑字段的红色窗口。问题是该字段看起来没有焦点(文本选择是灰色的)并且不可编辑(没有光标并且没有对击键的反应)。我可以用鼠标改变文本选择,但这就是全部。

任何有关错误的暗示?

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
    CCDirectorMac *director = (CCDirectorMac*) [CCDirector sharedDirector];
    [glView_ setFrameSize:NSMakeSize(1024,768)]; 
    [director setOpenGLView:glView_];
    [director setResizeMode:kCCDirectorResize_AutoScale];
    [glView_ setFrameSize:NSMakeSize(window_.frame.size.width,window_.frame.size.height-20)]; 
    [window_ setContentAspectRatio:NSMakeSize(1024,768)];
    [window_ setAcceptsMouseMovedEvents:NO];

    [self addOverlayWindow];

    //[director runWithScene:[MCGameScene scene]/*[HelloWorldLayer scene]*/];
}

- (void) addOverlayWindow;
{
    NSRect windowRect = [[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 XXXXXXXXX Label"];
    [textField setBezeled:YES];
    [textField setDrawsBackground:YES];
    [textField setEditable:YES];
    [textField setSelectable:YES];
    [textField setEnabled:YES];

    [uiView addSubview:textField];

    // None of these combinations works...
    //    [textField becomeFirstResponder];
    //    [uiWindow setInitialFirstResponder:textField];
//    [uiWindow makeFirstResponder:textField];
    //[window_ makeFirstResponder:textField];
      [window_ setInitialFirstResponder:textField];
//    [uiView setInitialFirstResponder:textField];
    //    [uiView makeFirstResponder:textField];

    [window_ addChildWindow:uiWindow ordered:NSWindowAbove];
}

先谢谢你的帮助, --Josef

0 个答案:

没有答案