Skip to content

Commit 83b5219

Browse files
authored
fix issue that can not close keyboard if using EditBox on iOS (#20336) (#20340)
1 parent 587bcab commit 83b5219

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

cocos/platform/ios/CCEAGLView-ios.mm

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,10 @@ - (CGRect) convertRectFromViewToSurface:(CGRect)rect
235235
// Pass the touches to the superview
236236
#pragma mark CCEAGLView - Touch Delegate
237237
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
238-
{
238+
{
239+
if (self.isKeyboardShown)
240+
[self closeKeyboardOpenedByEditBox];
241+
239242
UITouch* ids[IOS_MAX_TOUCHES_COUNT] = {0};
240243
float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
241244
float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};
@@ -546,4 +549,23 @@ - (void)onUIKeyboardNotification:(NSNotification *)notif
546549
}
547550
}
548551

552+
// Close the keyboard opened by EditBox
553+
-(void) closeKeyboardOpenedByEditBox
554+
{
555+
NSArray *subviews = self.subviews;
556+
557+
for(UIView* view in subviews)
558+
{
559+
if([view isKindOfClass:NSClassFromString(@"UITextView")] ||
560+
[view isKindOfClass:NSClassFromString(@"UITextField")])
561+
{
562+
if ([view isFirstResponder])
563+
{
564+
[view resignFirstResponder];
565+
return;
566+
}
567+
}
568+
}
569+
}
570+
549571
@end

0 commit comments

Comments
 (0)