From 8cde2faebccbea15c7e0c4df31402e6d3ce6a23f Mon Sep 17 00:00:00 2001 From: Richard Moe Gustavsen Date: Thu, 20 Mar 2014 10:52:10 +0100 Subject: iOS: don't scroll towards cursor during touch press MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While the user is touching the screen, postpone scrolling until we get a touch release. Scrolling in the middle of a touch sequence will change the coordinates under the touch, and cause some artefacts. Change-Id: I02ef420abaab780a459f014d4b4cfb75c8fbb725 Reviewed-by: Morten Johan Sørvig --- src/plugins/platforms/ios/qiosinputcontext.mm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/plugins/platforms/ios/qiosinputcontext.mm b/src/plugins/platforms/ios/qiosinputcontext.mm index ab4e3f38e7..9a2c55f7f2 100644 --- a/src/plugins/platforms/ios/qiosinputcontext.mm +++ b/src/plugins/platforms/ios/qiosinputcontext.mm @@ -55,6 +55,7 @@ BOOL m_keyboardVisible; BOOL m_keyboardVisibleAndDocked; BOOL m_ignoreKeyboardChanges; + BOOL m_touchPressWhileKeyboardVisible; BOOL m_keyboardHiddenByGesture; QRectF m_keyboardRect; QRectF m_keyboardEndRect; @@ -74,6 +75,7 @@ m_keyboardVisible = NO; m_keyboardVisibleAndDocked = NO; m_ignoreKeyboardChanges = NO; + m_touchPressWhileKeyboardVisible = NO; m_keyboardHiddenByGesture = NO; m_duration = 0; m_curve = UIViewAnimationCurveEaseOut; @@ -213,8 +215,16 @@ [super touchesMoved:touches withEvent:event]; } +- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event +{ + Q_ASSERT(m_keyboardVisibleAndDocked); + m_touchPressWhileKeyboardVisible = YES; + [super touchesBegan:touches withEvent:event]; +} + - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { + m_touchPressWhileKeyboardVisible = NO; [self performSelectorOnMainThread:@selector(touchesEndedPostDelivery) withObject:nil waitUntilDone:NO]; [super touchesEnded:touches withEvent:event]; } @@ -231,6 +241,8 @@ // the gesture, so we clear focus once more as a work-around. static_cast(QObjectPrivate::get(qApp->focusWindow()))->clearFocusObject(); } + } else { + m_context->scrollToCursor(); } } @@ -339,6 +351,13 @@ void QIOSInputContext::scrollToCursor() if (!isQtApplication() || !m_focusView) return; + if (m_keyboardListener->m_touchPressWhileKeyboardVisible) { + // Don't scroll to the cursor if the user is touching the screen. This + // interferes with selection and the 'hide keyboard' gesture. Instead + // we update scrolling upon touchEnd. + return; + } + UIView *view = m_keyboardListener->m_viewController.view; if (view.window != m_focusView.window) return; -- cgit v1.2.3