From 46f465202608d1e894d1a1524ec1249d1941d75e Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 15 Nov 2019 17:37:16 +0800 Subject: [PATCH 1/2] close keyboard when Done is pressed --- cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm b/cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm index 677374af4dcf..84de0e523aa2 100644 --- a/cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm +++ b/cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm @@ -395,6 +395,12 @@ - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r return YES; } + if ( self.keyboardReturnType == cocos2d::ui::EditBox::KeyboardReturnType::DONE && + [text isEqualToString: @"\n"] ) + { + [self closeKeyboard]; + } + // Prevent crashing undo bug http://stackoverflow.com/questions/433337/set-the-maximum-character-length-of-a-uitextfield if (range.length + range.location > textView.text.length) { return NO; From 89ec05c343ce8f9f31ea552904ade27fe6129b95 Mon Sep 17 00:00:00 2001 From: minggo Date: Fri, 15 Nov 2019 17:39:58 +0800 Subject: [PATCH 2/2] close keyboard when Done is pressed --- cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm b/cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm index 84de0e523aa2..eb33fd0a2bdd 100644 --- a/cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm +++ b/cocos/ui/UIEditBox/iOS/CCUIEditBoxIOS.mm @@ -389,18 +389,18 @@ - (BOOL)textViewShouldEndEditing:(UITextView *)textView - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { - int maxLength = getEditBoxImplIOS()->getMaxLength(); - if (maxLength < 0) - { - return YES; - } - if ( self.keyboardReturnType == cocos2d::ui::EditBox::KeyboardReturnType::DONE && [text isEqualToString: @"\n"] ) { [self closeKeyboard]; } + int maxLength = getEditBoxImplIOS()->getMaxLength(); + if (maxLength < 0) + { + return YES; + } + // Prevent crashing undo bug http://stackoverflow.com/questions/433337/set-the-maximum-character-length-of-a-uitextfield if (range.length + range.location > textView.text.length) { return NO;