fix issue that can not close keyboard if using EditBox on iOS (#20336) (#20340)

This commit is contained in:
minggo 2019-11-15 13:45:39 +08:00 committed by GitHub
parent 587bcabf44
commit 83b521991f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 23 additions and 1 deletions

View File

@ -235,7 +235,10 @@ Copyright (C) 2008 Apple Inc. All Rights Reserved.
// 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};
@ -546,4 +549,23 @@ namespace {
}
}
// 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