From de5185472651a6051a3c7b6e2519cc5f2b951a62 Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Tue, 25 Feb 2014 15:27:09 +0100 Subject: iOS: update keyboard rectangle when scrolling the screen MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When we scroll, the keyboard will change position relative to QScreen, even if it appears to stay put. For that reason we also need to update the keyboard rect after doing a scroll. Change-Id: I9bda2ab5b5e4970f488d3e69e44cf58e273f8fcd Reviewed-by: Tor Arne Vestbø --- src/plugins/platforms/ios/qiosinputcontext.mm | 32 ++++++++++++++++++++------- 1 file changed, 24 insertions(+), 8 deletions(-) (limited to 'src/plugins/platforms/ios/qiosinputcontext.mm') diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm index 4fe2cae15e..fff7de8170 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.mm +++ b/src/plugins/platforms/ios/qiosinputcontext.mm @@ -131,16 +131,11 @@ - (void) keyboardDidChangeFrame:(NSNotification *)notification { + Q_UNUSED(notification); if (m_ignoreKeyboardChanges) return; - m_keyboardRect = [self getKeyboardRect:notification]; - m_context->emitKeyboardRectChanged(); - BOOL visible = m_keyboardRect.intersects(fromCGRect([UIScreen mainScreen].bounds)); - if (m_keyboardVisible != visible) { - m_keyboardVisible = visible; - m_context->emitInputPanelVisibleChanged(); - } + [self handleKeyboardRectChanged]; // If the keyboard was visible and docked from before, this is just a geometry // change (normally caused by an orientation change). In that case, update scroll: @@ -172,6 +167,22 @@ m_context->scroll(0); } +- (void) handleKeyboardRectChanged +{ + QRectF rect = m_keyboardEndRect; + rect.moveTop(rect.y() + m_viewController.view.bounds.origin.y); + if (m_keyboardRect != rect) { + m_keyboardRect = rect; + m_context->emitKeyboardRectChanged(); + } + + BOOL visible = m_keyboardEndRect.intersects(fromCGRect([UIScreen mainScreen].bounds)); + if (m_keyboardVisible != visible) { + m_keyboardVisible = visible; + m_context->emitInputPanelVisibleChanged(); + } +} + @end QIOSInputContext::QIOSInputContext() @@ -295,10 +306,15 @@ void QIOSInputContext::scroll(int y) CGRect newBounds = view.bounds; newBounds.origin.y = y; + QPointer self = this; [UIView animateWithDuration:m_keyboardListener->m_duration delay:0 options:m_keyboardListener->m_curve animations:^{ view.bounds = newBounds; } - completion:0]; + completion:^(BOOL){ + if (self) + [m_keyboardListener handleKeyboardRectChanged]; + } + ]; } void QIOSInputContext::update(Qt::InputMethodQueries query) -- cgit v1.2.3