Skip to content

Commit

Permalink
fix issue that can not close keyboard if using EditBox on iOS (#20336) (
Browse files Browse the repository at this point in the history
  • Loading branch information
minggo authored Nov 15, 2019
1 parent 587bcab commit 83b5219
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion cocos/platform/ios/CCEAGLView-ios.mm
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,10 @@ - (CGRect) convertRectFromViewToSurface:(CGRect)rect
// Pass the touches to the superview
#pragma mark CCEAGLView - Touch Delegate
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
{
if (self.isKeyboardShown)
[self closeKeyboardOpenedByEditBox];

UITouch* ids[IOS_MAX_TOUCHES_COUNT] = {0};
float xs[IOS_MAX_TOUCHES_COUNT] = {0.0f};
float ys[IOS_MAX_TOUCHES_COUNT] = {0.0f};
Expand Down Expand Up @@ -546,4 +549,23 @@ - (void)onUIKeyboardNotification:(NSNotification *)notif
}
}

// Close the keyboard opened by EditBox
-(void) closeKeyboardOpenedByEditBox
{
NSArray *subviews = self.subviews;

for(UIView* view in subviews)
{
if([view isKindOfClass:NSClassFromString(@"UITextView")] ||
[view isKindOfClass:NSClassFromString(@"UITextField")])
{
if ([view isFirstResponder])
{
[view resignFirstResponder];
return;
}
}
}
}

@end

0 comments on commit 83b5219

Please sign in to comment.