diff options
author | Thierry Crozat | 2019-07-06 02:16:33 +0100 |
---|---|---|
committer | Thierry Crozat | 2019-07-06 17:00:27 +0100 |
commit | cfd66173bad8bb23ba7ba2d531fc5e98872212ce (patch) | |
tree | e1ecae249060cd4687e720f91526a2612e8e9773 | |
parent | b37ac333e1d95a05a871a8a233628974b47deda5 (diff) | |
download | scummvm-rg350-cfd66173bad8bb23ba7ba2d531fc5e98872212ce.tar.gz scummvm-rg350-cfd66173bad8bb23ba7ba2d531fc5e98872212ce.tar.bz2 scummvm-rg350-cfd66173bad8bb23ba7ba2d531fc5e98872212ce.zip |
IOS7: Hide input accessory toolbar when an external keyboard is connected
-rw-r--r-- | backends/platform/ios7/ios7_keyboard.h | 2 | ||||
-rw-r--r-- | backends/platform/ios7/ios7_keyboard.mm | 47 |
2 files changed, 45 insertions, 4 deletions
diff --git a/backends/platform/ios7/ios7_keyboard.h b/backends/platform/ios7/ios7_keyboard.h index af9e5be0be..44bb65e79b 100644 --- a/backends/platform/ios7/ios7_keyboard.h +++ b/backends/platform/ios7/ios7_keyboard.h @@ -34,11 +34,13 @@ } - (id)initWithFrame:(CGRect)frame; +- (void)dealloc; - (UITextView *)inputView; - (void)setInputDelegate:(id)delegate; - (void)handleKeyPress:(unichar)c; - (void)handleMainMenuKey; +- (void)prepareKeyboard:(NSNotification *)notification; - (void)showKeyboard; - (void)hideKeyboard; diff --git a/backends/platform/ios7/ios7_keyboard.mm b/backends/platform/ios7/ios7_keyboard.mm index 069cbd1900..9b3ca66981 100644 --- a/backends/platform/ios7/ios7_keyboard.mm +++ b/backends/platform/ios7/ios7_keyboard.mm @@ -36,7 +36,9 @@ } - (id)initWithKeyboard:(SoftKeyboard *)keyboard; -- (void)updateToolbarSize; +- (void)dealloc; +- (void)attachAccessoryView; +- (void)detachAccessoryView; @end @@ -54,7 +56,7 @@ //item.leadingBarButtonGroups = @[]; //item.trailingBarButtonGroups = @[]; - toolbar = [[[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)] autorelease]; + toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0f, 0.0f, 0.0f, 0.0f)]; toolbar.barTintColor = keyboard.backgroundColor; toolbar.tintColor = keyboard.tintColor; toolbar.translucent = NO; @@ -106,13 +108,30 @@ return self; } -- (void)updateToolbarSize { +-(void)dealloc { + [toolbar release]; + [scrollView release]; + [super dealloc]; +} + +- (void)attachAccessoryView { + self.inputAccessoryView.hidden = NO; + // Alternatively we could add/remove instead of show/hide the inpute accessory view +// self.inputAccessoryView = scrollView; +// [self reloadInputViews]; // We need at least a width of 768 pt for the toolbar. If we add more buttons this may need to be increased. toolbar.frame = CGRectMake(0, 0, MAX(768, [[UIScreen mainScreen] bounds].size.width), toolbar.frame.size.height); toolbar.bounds = toolbar.frame; scrollView.contentSize = toolbar.frame.size; } +- (void)detachAccessoryView { + self.inputAccessoryView.hidden = YES; + // Alternatively we could add/remove instead of show/hide the inpute accessory view +// self.inputAccessoryView = nil; +// [self reloadInputViews]; +} + - (NSArray *)keyCommands { UIKeyCommand *upArrow = [UIKeyCommand keyCommandWithInput: UIKeyInputUpArrow modifierFlags: 0 action: @selector(upArrow:)]; UIKeyCommand *downArrow = [UIKeyCommand keyCommandWithInput: UIKeyInputDownArrow modifierFlags: 0 action: @selector(downArrow:)]; @@ -227,9 +246,15 @@ inputDelegate = nil; inputView = [[TextInputHandler alloc] initWithKeyboard:self]; inputView.delegate = self; + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(prepareKeyboard:) name:UIKeyboardWillShowNotification object:nil]; return self; } +- (void)dealloc { + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [super dealloc]; +} + - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text { unichar c; if (text.length) { @@ -258,8 +283,22 @@ [inputDelegate handleMainMenuKey]; } +- (void)prepareKeyboard:(NSNotification *)notification { + // Check if a hardware keyboard is connected, and only show the accessory view if there isn't one. + // If there is a hardware keyboard, the software one will only contains the text assistance bar + // and will be small (less than 100 pt, but use a bit more in case it changes with future iOS versions). + // This only works with iOS 9 and above. For ealier version the keyboard size is fixed and instead it + // only shows part of the keyboard (which could be detected with the origin position, but that would + // depend on the current orientation and screen resolution). + NSDictionary* info = [notification userInfo]; + CGRect keyboardEndFrame = [[info objectForKey:UIKeyboardFrameEndUserInfoKey] CGRectValue]; + if (keyboardEndFrame.size.height < 140) + [inputView detachAccessoryView]; + else + [inputView attachAccessoryView]; +} + - (void)showKeyboard { - [inputView updateToolbarSize]; [inputView becomeFirstResponder]; } |