iOS: update keyboard rectangle when scrolling the screen

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ø <tor.arne.vestbo@digia.com>
This commit is contained in:
Richard Moe Gustavsen 2014-02-25 15:27:09 +01:00 committed by The Qt Project
parent 7b8d4cdb10
commit de51854726

View File

@ -131,16 +131,11 @@
- (void) keyboardDidChangeFrame:(NSNotification *)notification - (void) keyboardDidChangeFrame:(NSNotification *)notification
{ {
Q_UNUSED(notification);
if (m_ignoreKeyboardChanges) if (m_ignoreKeyboardChanges)
return; return;
m_keyboardRect = [self getKeyboardRect:notification];
m_context->emitKeyboardRectChanged();
BOOL visible = m_keyboardRect.intersects(fromCGRect([UIScreen mainScreen].bounds)); [self handleKeyboardRectChanged];
if (m_keyboardVisible != visible) {
m_keyboardVisible = visible;
m_context->emitInputPanelVisibleChanged();
}
// If the keyboard was visible and docked from before, this is just a geometry // 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: // change (normally caused by an orientation change). In that case, update scroll:
@ -172,6 +167,22 @@
m_context->scroll(0); 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 @end
QIOSInputContext::QIOSInputContext() QIOSInputContext::QIOSInputContext()
@ -295,10 +306,15 @@ void QIOSInputContext::scroll(int y)
CGRect newBounds = view.bounds; CGRect newBounds = view.bounds;
newBounds.origin.y = y; newBounds.origin.y = y;
QPointer<QIOSInputContext> self = this;
[UIView animateWithDuration:m_keyboardListener->m_duration delay:0 [UIView animateWithDuration:m_keyboardListener->m_duration delay:0
options:m_keyboardListener->m_curve options:m_keyboardListener->m_curve
animations:^{ view.bounds = newBounds; } animations:^{ view.bounds = newBounds; }
completion:0]; completion:^(BOOL){
if (self)
[m_keyboardListener handleKeyboardRectChanged];
}
];
} }
void QIOSInputContext::update(Qt::InputMethodQueries query) void QIOSInputContext::update(Qt::InputMethodQueries query)