diff --git a/cocos/ui/UIEditBox/Mac/CCUIEditBoxMac.mm b/cocos/ui/UIEditBox/Mac/CCUIEditBoxMac.mm index 51bc117a7b..6c6191e65c 100644 --- a/cocos/ui/UIEditBox/Mac/CCUIEditBoxMac.mm +++ b/cocos/ui/UIEditBox/Mac/CCUIEditBoxMac.mm @@ -48,7 +48,6 @@ self.keyboardReturnType = cocos2d::ui::EditBox::KeyboardReturnType::DEFAULT; [self createMultiLineTextField]; - [self.window.contentView addSubview:self.textInput]; } return self; @@ -96,7 +95,8 @@ [_textInput performSelector:@selector(setBackgroundColor:) withObject:[NSColor clearColor]]; if (![_textInput isKindOfClass:[NSTextView class]]) { - [_textInput performSelector:@selector(setBordered:) withObject:[NSNumber numberWithBool:NO]]; + [_textInput performSelector:@selector(setBordered:) + withObject:[NSNumber numberWithBool:NO]]; } _textInput.hidden = NO; _textInput.wantsLayer = YES; @@ -116,7 +116,6 @@ frame.size.width = rect.size.width; self.textInput.frame = frame; - [self.window makeFirstResponder:self.window.contentView]; } - (void)dealloc @@ -140,6 +139,11 @@ }else { [self.window makeFirstResponder:self.textInput]; } + + auto editbox = getEditBoxImplMac()->getEditBox(); + auto oldPos = editbox->getPosition(); + editbox->setPosition(oldPos + cocos2d::Vec2(10,20)); + editbox->setPosition(oldPos); } - (void)closeKeyboard @@ -189,30 +193,18 @@ return self.textInput.ccui_font.fontName ?: @""; } -- (void) hackingCodeForRefreshPosition -{ - [self.window.contentView addSubview:self.textInput]; - if (![self.textInput isKindOfClass:[NSTextView class]]) { - [self.textInput becomeFirstResponder]; - }else { - [self.window makeFirstResponder:self.textInput]; - } -} - - (void)setInputMode:(cocos2d::ui::EditBox::InputMode)inputMode { //multiline input if (inputMode == cocos2d::ui::EditBox::InputMode::ANY) { if (![self.textInput isKindOfClass:[NSTextView class]]) { [self createMultiLineTextField]; - [self hackingCodeForRefreshPosition]; } } else { if (self.dataInputMode != cocos2d::ui::EditBox::InputFlag::PASSWORD) { if (![self.textInput isKindOfClass:[NSTextField class]]) { [self createSingleLineTextField]; - [self hackingCodeForRefreshPosition]; } } } diff --git a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp index b91d72e2e8..517da4dafb 100644 --- a/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp +++ b/tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIEditBoxTest.cpp @@ -63,12 +63,13 @@ bool UIEditBoxTest::init() _editName->setPlaceHolder("Name:"); _editName->setPlaceholderFontColor(Color3B::WHITE); _editName->setMaxLength(8); - _editName->setFontSize(editBoxSize.height/2); + _editName->setFontSize(editBoxSize.height/2); _editName->setText("všŸ‘šŸ‘ŠšŸ’"); _editName->setReturnType(ui::EditBox::KeyboardReturnType::DONE); _editName->setDelegate(this); + _editName->setVisible(true); addChild(_editName); - + Button* button = Button::create("cocosui/animationbuttonnormal.png", "cocosui/animationbuttonpressed.png"); auto buttonSize = button->getContentSize(); @@ -87,10 +88,11 @@ bool UIEditBoxTest::init() _editPassword->setMaxLength(6); _editPassword->setInputFlag(ui::EditBox::InputFlag::PASSWORD); _editPassword->setInputMode(ui::EditBox::InputMode::SINGLE_LINE); - _editPassword->setFontSize(editBoxSize.height/2); + _editPassword->setFontSize(editBoxSize.height/2); _editPassword->setDelegate(this); + _editPassword->setVisible(true); addChild(_editPassword); - + auto buttonPassword = (ui::Button*)button->clone(); buttonPassword->setTitleText("Multiline"); buttonPassword->setPosition(_editPassword->getPosition() + Vec2(editBoxSize.width/2 + buttonSize.width/2, 0 )); @@ -111,6 +113,7 @@ bool UIEditBoxTest::init() _editEmail->setPlaceHolder("Email:"); _editEmail->setInputMode(ui::EditBox::InputMode::EMAIL_ADDRESS); _editEmail->setDelegate(this); + _editEmail->setVisible(true); _editEmailParent->addChild(_editEmail); //It is required to use setFontSize and setContentSize after adding it to the hierarchy, so that native EditBox get the right size _editEmail->setFontSize(30);