Skip to content

Commit 1c97e41

Browse files
authored
fix issue that can not close keyboard if using EditBox on iOS (#20336)
1 parent 49a9dff commit 1c97e41

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
@@ -360,7 +360,10 @@ - (CGRect) convertRectFromViewToSurface:(CGRect)rect
360360
// Pass the touches to the superview
361361
#pragma mark CCEAGLView - Touch Delegate
362362
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
363-
{
363+
{
364+
if (self.isKeyboardShown)
365+
[self closeKeyboardOpenedByEditBox];
366+
364367
UITouch* ids[IOS_MAX_TOUCHES_COUNT] = {0};
365368
float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
366369
float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};
@@ -671,4 +674,23 @@ - (void)onUIKeyboardNotification:(NSNotification *)notif
671674
}
672675
}
673676

677+
// Close the keyboard opened by EditBox
678+
-(void) closeKeyboardOpenedByEditBox
679+
{
680+
NSArray *subviews = self.subviews;
681+
682+
for(UIView* view in subviews)
683+
{
684+
if([view isKindOfClass:NSClassFromString(@"UITextView")] ||
685+
[view isKindOfClass:NSClassFromString(@"UITextField")])
686+
{
687+
if ([view isFirstResponder])
688+
{
689+
[view resignFirstResponder];
690+
return;
691+
}
692+
}
693+
}
694+
}
695+
674696
@end

0 commit comments

Comments
 (0)