@@ -1380,6 +1380,8 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
1380
1380
[self slk_hideAutoCompletionViewIfNeeded ];
1381
1381
}
1382
1382
1383
+ UIScrollView *scrollView = self.scrollViewProxy ;
1384
+
1383
1385
NSInteger curve = [notification.userInfo[UIKeyboardAnimationCurveUserInfoKey] integerValue ];
1384
1386
NSTimeInterval duration = [notification.userInfo[UIKeyboardAnimationDurationUserInfoKey] doubleValue ];
1385
1387
@@ -1390,10 +1392,10 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
1390
1392
// Scrolls to bottom only if the keyboard is about to show.
1391
1393
if (self.shouldScrollToBottomAfterKeyboardShows && self.keyboardStatus == SLKKeyboardStatusWillShow) {
1392
1394
if (self.isInverted ) {
1393
- [self .scrollViewProxy slk_scrollToTopAnimated: YES ];
1395
+ [scrollView slk_scrollToTopAnimated: YES ];
1394
1396
}
1395
1397
else {
1396
- [self .scrollViewProxy slk_scrollToBottomAnimated: YES ];
1398
+ [scrollView slk_scrollToBottomAnimated: YES ];
1397
1399
}
1398
1400
}
1399
1401
};
@@ -1403,6 +1405,20 @@ - (void)slk_willShowOrHideKeyboard:(NSNotification *)notification
1403
1405
// Second condition: check if the height of the keyboard changed.
1404
1406
if (!CGRectEqualToRect (beginFrame, endFrame) || fabs (previousKeyboardHeight - self.keyboardHC .constant ) > 0.0 )
1405
1407
{
1408
+ // Content Offset correction if not inverted and not auto-completing.
1409
+ if (!self.isInverted && !self.isAutoCompleting ) {
1410
+
1411
+ CGFloat scrollViewHeight = self.scrollViewHC .constant ;
1412
+ CGFloat keyboardHeight = self.keyboardHC .constant ;
1413
+ CGSize contentSize = scrollView.contentSize ;
1414
+ CGPoint contentOffset = scrollView.contentOffset ;
1415
+
1416
+ CGFloat newOffset = MIN (contentSize.height - scrollViewHeight,
1417
+ contentOffset.y + keyboardHeight - previousKeyboardHeight);
1418
+
1419
+ scrollView.contentOffset = CGPointMake (contentOffset.x , newOffset);
1420
+ }
1421
+
1406
1422
// Only for this animation, we set bo to bounce since we want to give the impression that the text input is glued to the keyboard.
1407
1423
[self .view slk_animateLayoutIfNeededWithDuration: duration
1408
1424
bounce: NO
0 commit comments